File manager - Edit - /home/xfekoga/rooftopcleaners/wp-includes/widgets/controls.tar
Back
js/controls.js 0000644 00000072252 15174424610 0007375 0 ustar 00 var consultstreet = { /** * An object containing definitions for controls. */ control: { /** * The color control. */ 'consultstreet-color': { /** * Init the control. * * @param {object} [control] The customizer control object. * @returns {void} */ init: function ( control ) { var self = this; // Render the template. self.template( control ); // Init the control. consultstreet.input.color.init( control ); }, /** * Render the template. * * @param {object} [control] The customizer control object. * @returns {void} */ template: function ( control ) { control.container.html( consultstreet.input.color.getTemplate( { label: control.params.label, description: control.params.description, 'data-id': control.id, mode: control.params.mode, inputAttrs: control.params.inputAttrs, 'data-palette': control.params.palette, 'data-default-color': control.params.default, 'data-alpha': control.params.choices.alpha, value: control.setting._value } ) ); } } }, /** * An object containing definitions for input fields. */ input: { /** * Color input fields. */ color: { /** * Get the HTML for color inputs. * * @param {object} [data] The arguments. * @returns {string} */ getTemplate: function ( data ) { var html = ''; data = _.defaults( data, { label: '', description: '', mode: 'full', inputAttrs: '', 'data-palette': data['data-palette'] ? data['data-palette'] : true, 'data-default-color': data['data-default-color'] ? data['data-default-color'] : '', 'data-alpha': data['data-alpha'] ? data['data-alpha'] : false, value: '', 'data-id': '' } ); html += '<label>'; if ( data.label ) { html += '<span class="customize-control-title">' + data.label + '</span>'; } if ( data.description ) { html += '<span class="description customize-control-description">' + data.description + '</span>'; } html += '</label>'; html += '<input type="text" data-type="' + data.mode + '" ' + data.inputAttrs + ' data-palette="' + data['data-palette'] + '" data-default-color="' + data['data-default-color'] + '" data-alpha="' + data['data-alpha'] + '" value="' + data.value + '" class="consultstreet-color-control" data-id="' + data['data-id'] + '"/>'; return ( '<div class="consultstreet-input-container" data-id="' + data.id + '">' + html + '</div>' ); }, /** * Init the control. * * @param {object} [control] The control object. * @returns {void} */ init: function ( control ) { var picker = jQuery( '.consultstreet-color-control[data-id="' + control.id + '"]' ), clear; control.choices = control.choices || {}; if ( _.isEmpty( control.choices ) && control.params.choices ) { control.choices = control.params.choices; } // If we have defined any extra choices, make sure they are passed-on to Iris. if ( !_.isEmpty( control.choices ) ) { picker.wpColorPicker( control.choices ); } // Tweaks to make the "clear" buttons work. setTimeout( function () { clear = jQuery( '.consultstreet-input-container[data-id="' + control.id + '"] .wp-picker-clear' ); if ( clear.length ) { clear.click( function () { control.setting.set( '' ); } ); } }, 200 ); // Saves our settings to the WP API picker.wpColorPicker( { change: function () { // Small hack: the picker needs a small delay setTimeout( function () { control.setting.set( picker.val() ); }, 20 ); } } ); } } }, /** * An object containing definitions for settings. */ setting: { /** * Gets the value of a setting. * * This is a helper function that allows us to get the value of * control[key1][key2] for example, when the setting used in the * customizer API is "control". * * @param {string} [setting] The setting for which we're getting the value. * @returns {mixed} Depends on the value. */ get: function ( setting ) { var parts = setting.split( '[' ), foundSetting = '', foundInStep = 0, currentVal = ''; _.each( parts, function ( part, i ) { part = part.replace( ']', '' ); if ( 0 === i ) { foundSetting = part; } else { foundSetting += '[' + part + ']'; } if ( !_.isUndefined( wp.customize.instance( foundSetting ) ) ) { currentVal = wp.customize.instance( foundSetting ).get(); foundInStep = i; } if ( foundInStep < i ) { if ( _.isObject( currentVal ) && !_.isUndefined( currentVal[part] ) ) { currentVal = currentVal[part]; } } } ); return currentVal; }, /** * Sets the value of a setting. * * This function is a bit complicated because there any many scenarios to consider. * Example: We want to save the value for my_setting[something][3][something-else]. * The control's setting is my_setting[something]. * So we need to find that first, then figure out the remaining parts, * merge the values recursively to avoid destroying my_setting[something][2] * and also take into account any defined "key" arguments which take this even deeper. * * @param {object|string} [element] The DOM element whose value has changed, * or an ID. * @param {mixed} [value] Depends on the control-type. * @param {string} [key] If we only want to save an item in an object * we can define the key here. * @returns {void} */ set: function ( element, value, key ) { var setting, parts, currentNode = '', foundNode = '', subSettingObj = {}, currentVal, subSetting, subSettingParts; // Get the setting from the element. setting = element; if ( _.isObject( element ) ) { if ( jQuery( element ).attr( 'data-id' ) ) { setting = element.attr( 'data-id' ); } else { setting = element.parents( '[data-id]' ).attr( 'data-id' ); } } ( parts = setting.split( '[' ) ), // Find the setting we're using in the control using the customizer API. _.each( parts, function ( part, i ) { part = part.replace( ']', '' ); // The current part of the setting. currentNode = 0 === i ? part : '[' + part + ']'; // When we find the node, get the value from it. // In case of an object we'll need to merge with current values. if ( !_.isUndefined( wp.customize.instance( currentNode ) ) ) { foundNode = currentNode; currentVal = wp.customize.instance( foundNode ).get(); } } ); // Get the remaining part of the setting that was unused. subSetting = setting.replace( foundNode, '' ); // If subSetting is not empty, then we're dealing with an object // and we need to dig deeper and recursively merge the values. if ( '' !== subSetting ) { if ( !_.isObject( currentVal ) ) { currentVal = {}; } if ( '[' === subSetting.charAt( 0 ) ) { subSetting = subSetting.replace( '[', '' ); } subSettingParts = subSetting.split( '[' ); _.each( subSettingParts, function ( subSettingPart, i ) { subSettingParts[i] = subSettingPart.replace( ']', '' ); } ); // If using a key, we need to go 1 level deeper. if ( key ) { subSettingParts.push( key ); } // Converting to a JSON string and then parsing that to an object // may seem a bit hacky and crude but it's efficient and works. subSettingObj = '{"' + subSettingParts.join( '":{"' ) + '":"' + value + '"' + '}'.repeat( subSettingParts.length ); subSettingObj = JSON.parse( subSettingObj ); // Recursively merge with current value. jQuery.extend( true, currentVal, subSettingObj ); value = currentVal; } else { if ( key ) { currentVal = !_.isObject( currentVal ) ? {} : currentVal; currentVal[key] = value; value = currentVal; } } wp.customize.control( foundNode ).setting.set( value ); } } }; ( function () { 'use strict'; /** * A dynamic color-alpha control. * * @class * @augments wp.customize.Control * @augments wp.customize.Class */ wp.customize.consultstreetDynamicControl = wp.customize.Control.extend( { initialize: function ( id, options ) { var control = this, args = options || {}; args.params = args.params || {}; if ( !args.params.type ) { args.params.type = 'consultstreet-generic'; } if ( !args.params.content ) { args.params.content = jQuery( '<li></li>' ); args.params.content.attr( 'id', 'customize-control-' + id.replace( /]/g, '' ).replace( /\[/g, '-' ) ); args.params.content.attr( 'class', 'customize-control customize-control-' + args.params.type ); } control.propertyElements = []; wp.customize.Control.prototype.initialize.call( control, id, args ); }, /** * Add bidirectional data binding links between inputs and the setting(s). * * This is copied from wp.customize.Control.prototype.initialize(). It * should be changed in Core to be applied once the control is embedded. * * @private * @returns {void} */ _setUpSettingRootLinks: function () { var control = this, nodes = control.container.find( '[data-customize-setting-link]' ); nodes.each( function () { var node = jQuery( this ); wp.customize( node.data( 'customizeSettingLink' ), function ( setting ) { var element = new wp.customize.Element( node ); control.elements.push( element ); element.sync( setting ); element.set( setting() ); } ); } ); }, /** * Add bidirectional data binding links between inputs and the setting properties. * * @private * @returns {void} */ _setUpSettingPropertyLinks: function () { var control = this, nodes; if ( !control.setting ) { return; } nodes = control.container.find( '[data-customize-setting-property-link]' ); nodes.each( function () { var node = jQuery( this ), element, propertyName = node.data( 'customizeSettingPropertyLink' ); element = new wp.customize.Element( node ); control.propertyElements.push( element ); element.set( control.setting()[propertyName] ); element.bind( function ( newPropertyValue ) { var newSetting = control.setting(); if ( newPropertyValue === newSetting[propertyName] ) { return; } newSetting = _.clone( newSetting ); newSetting[propertyName] = newPropertyValue; control.setting.set( newSetting ); } ); control.setting.bind( function ( newValue ) { if ( newValue[propertyName] !== element.get() ) { element.set( newValue[propertyName] ); } } ); } ); }, /** * @inheritdoc */ ready: function () { var control = this; control._setUpSettingRootLinks(); control._setUpSettingPropertyLinks(); wp.customize.Control.prototype.ready.call( control ); control.deferred.embedded.done( function () { control.initConsultStreetControl( control ); } ); }, /** * Embed the control in the document. * * Override the embed() method to do nothing, * so that the control isn't embedded on load, * unless the containing section is already expanded. * * @returns {void} */ embed: function () { var control = this, sectionId = control.section(); if ( !sectionId ) { return; } wp.customize.section( sectionId, function ( section ) { if ( 'consultstreet-expanded' === section.params.type || section.expanded() || wp.customize.settings.autofocus.control === control.id ) { control.actuallyEmbed(); } else { section.expanded.bind( function ( expanded ) { if ( expanded ) { control.actuallyEmbed(); } } ); } } ); }, /** * Deferred embedding of control when actually * * This function is called in Section.onChangeExpanded() so the control * will only get embedded when the Section is first expanded. * * @returns {void} */ actuallyEmbed: function () { var control = this; if ( 'resolved' === control.deferred.embedded.state() ) { return; } control.renderContent(); control.deferred.embedded.resolve(); // This triggers control.ready(). }, /** * This is not working with autofocus. * * @param {object} [args] Args. * @returns {void} */ focus: function ( args ) { var control = this; control.actuallyEmbed(); wp.customize.Control.prototype.focus.call( control, args ); }, /** * Additional actions that run on ready. * * @param {object} [args] Args. * @returns {void} */ initConsultStreetControl: function ( control ) { if ( 'undefined' !== typeof consultstreet.control[control.params.type] ) { consultstreet.control[control.params.type].init( control ); return; } // Save the value this.container.on( 'change keyup paste click', 'input', function () { control.setting.set( jQuery( this ).val() ); } ); }, consultstreetValidateCSSValue: function ( value ) { var validUnits = [ 'rem', 'em', 'ex', '%', 'px', 'cm', 'mm', 'pt' ], numericValue, unit; // 0 is always a valid value, and we can't check calc() values effectively. if ( '0' === value || ( 0 <= value.indexOf( 'calc(' ) && 0 <= value.indexOf( ')' ) ) ) { return true; } // Get the numeric value. numericValue = parseFloat( value ); // Get the unit unit = value.replace( numericValue, '' ); // Check the validity of the numeric value and units. if ( isNaN( numericValue ) || -1 === jQuery.inArray( unit, validUnits ) ) { return false; } return true; } } ); }() ); _.each( consultstreet.control, function ( obj, type ) { wp.customize.controlConstructor[ type ] = wp.customize.consultstreetDynamicControl.extend( {} ); } ); /** * Control: Slider. */ wp.customize.controlConstructor['consultstreet-slider'] = wp.customize.Control.extend( { // When we're finished loading continue processing ready: function () { 'use strict'; var control = this, changeAction = ( 'postMessage' === control.setting.transport ) ? 'mousemove change' : 'change', slider = control.container.find( '.consultstreet-slider' ), input = control.container.find( 'input.slider-input' ), min = Number( input.attr( 'min' ) ), max = Number( input.attr( 'max' ) ), step = Number( input.attr( 'step' ) ), $this, val; slider.slider( { range: 'min', min: min, max: max, value: input.val(), step: step, slide: function ( event, ui ) { // Trigger keyup in input. input.val( ui.value ).keyup(); }, change: function ( event, ui ) { // Save the values. control.initConsultStreetControl(); } } ); input.on( 'change keyup paste', function () { $this = jQuery( this ); val = $this.val(); slider.slider( 'value', val ); } ); // Change on input. control.container.on( 'change keyup paste', '.customize-control-content input.slider-input', function () { control.setting.set( jQuery( this ).val() ); } ); // Reset. control.container.find( '.slider-reset' ).on( 'click', function () { input.attr( 'value', control.params.default.slider ); slider.slider( 'value', control.params.default.slider ); control.setting.set( input.val() ); } ); // Init the control. if ( !_.isUndefined( window.consultstreetControlLoader ) && _.isFunction( consultstreetControlLoader ) ) { consultstreetControlLoader( control ); } else { control.initConsultStreetControl(); } }, initConsultStreetControl: function () { var control = this, subControls = control.params.choices.controls, value = {}, subsArray = [], i; _.each( subControls, function ( v, i ) { if ( true === v ) { subsArray.push( i ); } } ); for ( i = 0; i < subsArray.length; i++ ) { value[subsArray[i]] = control.setting._value[subsArray[i]]; control.updateSliderValue( subsArray[i], value ); } }, /** * Updates the value. */ updateSliderValue: function ( context, value ) { var control = this; control.container.on( 'change keyup paste', 'input.slider-input', function () { value['slider'] = jQuery( this ).val(); value['suffix'] = jQuery( this ).next().val(); // Save the value control.saveValue( value ); } ); // TODO: find a way to merge event. control.container.on( 'click', '.slider-reset', function () { value['slider'] = jQuery( this ).siblings('.slider-input').val(); value['suffix'] = jQuery( this ).prev().val(); // Save the value control.saveValue( value ); } ); }, /** * Saves the value. */ saveValue: function ( value ) { var control = this, newValue = {}; _.each( value, function ( newSubValue, i ) { newValue[i] = newSubValue; } ); control.setting.set( newValue ); } } ); /** * Control: Text. */ wp.customize.controlConstructor['consultstreet-text'] = wp.customize.Control.extend( { // When we're finished loading continue processing. ready: function () { 'use strict'; var control = this; // Save the values control.container.on( 'change keyup paste', '.customize-control-content input', function () { control.setting.set( jQuery( this ).val() ); } ); } } ); /** * Control: Sortable. */ /* global consultstreetControlLoader */ wp.customize.controlConstructor['consultstreet-sortable'] = wp.customize.Control.extend( { // When we're finished loading continue processing ready: function () { 'use strict'; var control = this; // Init the control. if ( !_.isUndefined( window.consultstreetControlLoader ) && _.isFunction( consultstreetControlLoader ) ) { consultstreetControlLoader( control ); } else { control.initConsultStreetControl(); } }, initConsultStreetControl: function () { 'use strict'; var control = this; control.container.find( '.consultstreet-controls-loading-spinner' ).hide(); // Set the sortable container. control.sortableContainer = control.container.find( 'ul.sortable' ).first(); // Init sortable. control.sortableContainer .sortable( { // Update value when we stop sorting. stop: function () { control.updateValue(); } } ) .disableSelection() .find( 'li' ) .each( function () { // Enable/disable options when we click on the eye of Thundera. jQuery( this ) .find( 'i.visibility' ) .click( function () { jQuery( this ) .toggleClass( 'dashicons-visibility-faint' ) .parents( 'li:eq(0)' ) .toggleClass( 'invisible' ); } ); } ) .click( function () { // Update value on click. control.updateValue(); } ); }, /** * Updates the sorting list */ updateValue: function () { 'use strict'; var control = this, newValue = []; this.sortableContainer.find( 'li' ).each( function () { if ( !jQuery( this ).is( '.invisible' ) ) { newValue.push( jQuery( this ).data( 'value' ) ); } } ); control.setting.set( newValue ); } } ); /** * Control: Radio image. */ wp.customize.controlConstructor['consultstreet-radio-image'] = wp.customize.consultstreetDynamicControl.extend( {} ); /** * Control: Toggle. */ wp.customize.controlConstructor['consultstreet-toggle'] = wp.customize.consultstreetDynamicControl.extend( { // When we're finished loading continue processing ready: function () { 'use strict'; var control = this; // Init the control. if ( !_.isUndefined( window.consultstreetControlLoader ) && _.isFunction( consultstreetControlLoader ) ) { consultstreetControlLoader( control ); } else { control.initConsultStreetControl(); } }, initConsultStreetControl: function () { var control = this, checkboxValue = control.setting._value; // Save the value this.container.on( 'change', 'input', function () { checkboxValue = jQuery( this ).is( ':checked' ) ? true : false; control.setting.set( checkboxValue ); } ); } } ); /** * Control: Radio Buttonset. */ wp.customize.controlConstructor['consultstreet-radio-buttonset'] = wp.customize.Control.extend( {} ); /** * Control: Dimensions. */ ; /* global dimensionsconsultstreetL10n */ /* global consultstreetControlLoader */ wp.customize.controlConstructor['consultstreet-dimensions'] = wp.customize.consultstreetDynamicControl.extend( { // When we're finished loading continue processing ready: function () { 'use strict'; var control = this; // Init the control. if ( !_.isUndefined( window.consultstreetControlLoader ) && _.isFunction( consultstreetControlLoader ) ) { consultstreetControlLoader( control ); } else { control.initConsultStreetControl(); } }, initConsultStreetControl: function () { var control = this, subControls = control.params.choices.controls, value = {}, subsArray = [], i; _.each( subControls, function ( v, i ) { if ( true === v ) { subsArray.push( i ); } } ); for ( i = 0; i < subsArray.length; i++ ) { value[subsArray[i]] = control.setting._value[subsArray[i]]; control.updateDimensionsValue( subsArray[i], value ); } }, /** * Updates the value. */ updateDimensionsValue: function ( context, value ) { var control = this; control.container.on( 'change keyup paste', '.' + context + ' input', function () { value[context] = jQuery( this ).val(); // Notifications. control.consultstreetNotifications(); // Save the value control.saveValue( value ); } ); }, /** * Saves the value. */ saveValue: function ( value ) { var control = this, newValue = {}; _.each( value, function ( newSubValue, i ) { newValue[i] = newSubValue; } ); control.setting.set( newValue ); }, /** * Handles notifications. */ consultstreetNotifications: function () { var control = this; wp.customize( control.id, function ( setting ) { setting.bind( function ( value ) { var code = 'long_title', subs = {}, message; setting.notifications.remove( code ); _.each( ['top', 'right', 'bottom', 'left'], function ( direction ) { if ( !_.isUndefined( value[direction] ) ) { if ( false === control.consultstreetValidateCSSValue( value[direction] ) ) { subs[direction] = dimensionsconsultstreetL10n[direction]; } else { delete subs[direction]; } } } ); if ( !_.isEmpty( subs ) ) { message = dimensionsconsultstreetL10n['invalid-value'] + ' (' + _.values( subs ).toString() + ') '; setting.notifications.add( code, new wp.customize.Notification( code, { type: 'warning', message: message } ) ); } else { setting.notifications.remove( code ); } } ); } ); } } ); /** * Control: Background. */ ; /* global consultstreetControlLoader */ wp.customize.controlConstructor['consultstreet-background'] = wp.customize.Control.extend( { // When we're finished loading continue processing ready: function () { 'use strict'; var control = this; // Init the control. if ( !_.isUndefined( window.consultstreetControlLoader ) && _.isFunction( consultstreetControlLoader ) ) { consultstreetControlLoader( control ); } else { control.initConsultStreetControl(); } }, initConsultStreetControl: function () { var control = this, value = control.setting._value, picker = control.container.find( '.consultstreet-color-control' ); // Hide unnecessary controls if the value doesn't have an image. if ( _.isUndefined( value['background-image'] ) || '' === value['background-image'] ) { control.container.find( '.background-wrapper > .background-repeat' ).hide(); control.container.find( '.background-wrapper > .background-position' ).hide(); control.container.find( '.background-wrapper > .background-size' ).hide(); control.container.find( '.background-wrapper > .background-attachment' ).hide(); } // Color. picker.wpColorPicker( { change: function () { setTimeout( function () { control.saveValue( 'background-color', picker.val() ); }, 100 ); } } ); // Background-Repeat. control.container.on( 'change', '.background-repeat select', function () { control.saveValue( 'background-repeat', jQuery( this ).val() ); } ); // Background-Size. control.container.on( 'change click', '.background-size input', function () { control.saveValue( 'background-size', jQuery( this ).val() ); } ); // Background-Position. control.container.on( 'change', '.background-position select', function () { control.saveValue( 'background-position', jQuery( this ).val() ); } ); // Background-Attachment. control.container.on( 'change click', '.background-attachment input', function () { control.saveValue( 'background-attachment', jQuery( this ).val() ); } ); // Background-Image. control.container.on( 'click', '.background-image-upload-button', function ( e ) { var image = wp.media( {multiple: false} ).open().on( 'select', function () { // This will return the selected image from the Media Uploader, the result is an object. var uploadedImage = image.state().get( 'selection' ).first(), previewImage = uploadedImage.toJSON().sizes.full.url, imageUrl, imageID, imageWidth, imageHeight, preview, removeButton; if ( !_.isUndefined( uploadedImage.toJSON().sizes.medium ) ) { previewImage = uploadedImage.toJSON().sizes.medium.url; } else if ( !_.isUndefined( uploadedImage.toJSON().sizes.thumbnail ) ) { previewImage = uploadedImage.toJSON().sizes.thumbnail.url; } imageUrl = uploadedImage.toJSON().sizes.full.url; imageID = uploadedImage.toJSON().id; imageWidth = uploadedImage.toJSON().width; imageHeight = uploadedImage.toJSON().height; // Show extra controls if the value has an image. if ( '' !== imageUrl ) { control.container.find( '.background-wrapper > .background-repeat, .background-wrapper > .background-position, .background-wrapper > .background-size, .background-wrapper > .background-attachment' ).show(); } control.saveValue( 'background-image', imageUrl ); preview = control.container.find( '.placeholder, .thumbnail' ); removeButton = control.container.find( '.background-image-upload-remove-button' ); if ( preview.length ) { preview.removeClass().addClass( 'thumbnail thumbnail-image' ).html( '<img src="' + previewImage + '" alt="" />' ); } if ( 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', '' ); preview = control.container.find( '.placeholder, .thumbnail' ); removeButton = control.container.find( '.background-image-upload-remove-button' ); // Hide unnecessary controls. control.container.find( '.background-wrapper > .background-repeat' ).hide(); control.container.find( '.background-wrapper > .background-position' ).hide(); control.container.find( '.background-wrapper > .background-size' ).hide(); control.container.find( '.background-wrapper > .background-attachment' ).hide(); if ( preview.length ) { preview.removeClass().addClass( 'placeholder' ).html( 'No file selected' ); } if ( removeButton.length ) { removeButton.hide(); } } ); }, /** * Saves the value. */ saveValue: function ( property, value ) { var control = this, input = jQuery( '#customize-control-' + control.id.replace( '[', '-' ).replace( ']', '' ) + ' .background-hidden-value' ), val = control.setting._value; val[property] = value; jQuery( input ).attr( 'value', JSON.stringify( val ) ).trigger( 'change' ); control.setting.set( val ); } } ); /** * Control: Editor. */ wp.customize.controlConstructor['consultstreet-editor'] = wp.customize.consultstreetDynamicControl.extend( { initConsultStreetControl: function () { var control = this, element = control.container.find( 'textarea' ), editor; control_id = control.id.replace( '[', '' ).replace( ']', '' ); var id = 'consultstreet-editor-' + control_id; wp.editor.initialize( id, { tinymce: { wpautop: true }, quicktags: true, mediaButtons: true } ); editor = tinyMCE.get( id ); if ( editor ) { editor.onChange.add( function ( ed ) { var content; ed.save(); content = editor.getContent(); element.val( content ).trigger( 'change' ); wp.customize.instance( control.id ).set( content ); } ); } } } ); js/wp-color-picker-alpha.js 0000644 00000036361 15174424610 0011633 0 ustar 00 /**! * wp-color-picker-alpha * * Overwrite Automattic Iris for enabled Alpha Channel in wpColorPicker * Only run in input and is defined data alpha in true * * Version: 2.1.3 * https://github.com/kallookoo/wp-color-picker-alpha * Licensed under the GPLv2 license or later. */ ( function( $ ) { // Prevent double-init. if ( $.wp.wpColorPicker.prototype._hasAlpha ) { return; } // Variable for some backgrounds ( grid ) var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAAHnlligAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHJJREFUeNpi+P///4EDBxiAGMgCCCAGFB5AADGCRBgYDh48CCRZIJS9vT2QBAggFBkmBiSAogxFBiCAoHogAKIKAlBUYTELAiAmEtABEECk20G6BOmuIl0CIMBQ/IEMkO0myiSSraaaBhZcbkUOs0HuBwDplz5uFJ3Z4gAAAABJRU5ErkJggg==', // html stuff for wpColorPicker copy of the original color-picker.js _after = '<div class="wp-picker-holder" />', _wrap = '<div class="wp-picker-container" />', _button = '<input type="button" class="button button-small" />', // Prevent CSS issues in < WordPress 4.9 _deprecated = ( wpColorPickerL10n.current !== undefined ); // Declare some global variables when is deprecated or not if ( _deprecated ) { var _before = '<a tabindex="0" class="wp-color-result" />'; } else { var _before = '<button type="button" class="button wp-color-result" aria-expanded="false"><span class="wp-color-result-text"></span></button>', _wrappingLabel = '<label></label>', _wrappingLabelText = '<span class="screen-reader-text"></span>'; } /** * Overwrite Color * for enable support rbga */ Color.fn.toString = function() { if ( this._alpha < 1 ) return this.toCSS( 'rgba', this._alpha ).replace( /\s+/g, '' ); var hex = parseInt( this._color, 10 ).toString( 16 ); if ( this.error ) return ''; if ( hex.length < 6 ) hex = ( '00000' + hex ).substr( -6 ); return '#' + hex; }; /** * Overwrite wpColorPicker */ $.widget( 'wp.wpColorPicker', $.wp.wpColorPicker, { _hasAlpha: true, /** * @summary Creates the color picker. * * Creates the color picker, sets default values, css classes and wraps it all in HTML. * * @since 3.5.0 * * @access private * * @returns {void} */ _create: function() { // Return early if Iris support is missing. if ( ! $.support.iris ) { return; } var self = this, el = self.element; // Override default options with options bound to the element. $.extend( self.options, el.data() ); // Create a color picker which only allows adjustments to the hue. if ( self.options.type === 'hue' ) { return self._createHueOnly(); } // Bind the close event. self.close = $.proxy( self.close, self ); self.initialValue = el.val(); // Add a CSS class to the input field. el.addClass( 'wp-color-picker' ); if ( _deprecated ) { el.hide().wrap( _wrap ); self.wrap = el.parent(); self.toggler = $( _before ) .insertBefore( el ) .css( { backgroundColor : self.initialValue } ) .attr( 'title', wpColorPickerL10n.pick ) .attr( 'data-current', wpColorPickerL10n.current ); self.pickerContainer = $( _after ).insertAfter( el ); self.button = $( _button ).addClass('hidden'); } else { /* * Check if there's already a wrapping label, e.g. in the Customizer. * If there's no label, add a default one to match the Customizer template. */ if ( ! el.parent( 'label' ).length ) { // Wrap the input field in the default label. el.wrap( _wrappingLabel ); // Insert the default label text. self.wrappingLabelText = $( _wrappingLabelText ) .insertBefore( el ) .text( wpColorPickerL10n.defaultLabel ); } /* * At this point, either it's the standalone version or the Customizer * one, we have a wrapping label to use as hook in the DOM, let's store it. */ self.wrappingLabel = el.parent(); // Wrap the label in the main wrapper. self.wrappingLabel.wrap( _wrap ); // Store a reference to the main wrapper. self.wrap = self.wrappingLabel.parent(); // Set up the toggle button and insert it before the wrapping label. self.toggler = $( _before ) .insertBefore( self.wrappingLabel ) .css( { backgroundColor: self.initialValue } ); // Set the toggle button span element text. self.toggler.find( '.wp-color-result-text' ).text( wpColorPickerL10n.pick ); // Set up the Iris container and insert it after the wrapping label. self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel ); // Store a reference to the Clear/Default button. self.button = $( _button ); } // Set up the Clear/Default button. if ( self.options.defaultColor ) { self.button.addClass( 'wp-picker-default' ).val( wpColorPickerL10n.defaultString ); if ( ! _deprecated ) { self.button.attr( 'aria-label', wpColorPickerL10n.defaultAriaLabel ); } } else { self.button.addClass( 'wp-picker-clear' ).val( wpColorPickerL10n.clear ); if ( ! _deprecated ) { self.button.attr( 'aria-label', wpColorPickerL10n.clearAriaLabel ); } } if ( _deprecated ) { el.wrap( '<span class="wp-picker-input-wrap" />' ).after( self.button ); } else { // Wrap the wrapping label in its wrapper and append the Clear/Default button. self.wrappingLabel .wrap( '<span class="wp-picker-input-wrap hidden" />' ) .after( self.button ); /* * The input wrapper now contains the label+input+Clear/Default button. * Store a reference to the input wrapper: we'll use this to toggle * the controls visibility. */ self.inputWrapper = el.closest( '.wp-picker-input-wrap' ); } el.iris( { target: self.pickerContainer, hide: self.options.hide, width: self.options.width, mode: self.options.mode, palettes: self.options.palettes, /** * @summary Handles the onChange event if one has been defined in the options. * * Handles the onChange event if one has been defined in the options and additionally * sets the background color for the toggler element. * * @since 3.5.0 * * @param {Event} event The event that's being called. * @param {HTMLElement} ui The HTMLElement containing the color picker. * * @returns {void} */ change: function( event, ui ) { if ( self.options.alpha ) { self.toggler.css( { 'background-image' : 'url(' + image + ')' } ); if ( _deprecated ) { self.toggler.html( '<span class="color-alpha" />' ); } else { self.toggler.css( { 'position' : 'relative' } ); if ( self.toggler.find('span.color-alpha').length == 0 ) { self.toggler.append('<span class="color-alpha" />'); } } self.toggler.find( 'span.color-alpha' ).css( { 'width' : '30px', 'height' : '28px', 'position' : 'absolute', 'top' : 0, 'left' : 0, 'border-top-left-radius' : '2px', 'border-bottom-left-radius' : '2px', 'background' : ui.color.toString() } ); } else { self.toggler.css( { backgroundColor : ui.color.toString() } ); } if ( $.isFunction( self.options.change ) ) { self.options.change.call( this, event, ui ); } } } ); el.val( self.initialValue ); self._addListeners(); // Force the color picker to always be closed on initial load. if ( ! self.options.hide ) { self.toggler.click(); } }, /** * @summary Binds event listeners to the color picker. * * @since 3.5.0 * * @access private * * @returns {void} */ _addListeners: function() { var self = this; /** * @summary Prevent any clicks inside this widget from leaking to the top and closing it. * * @since 3.5.0 * * @param {Event} event The event that's being called. * * @returs {void} */ self.wrap.on( 'click.wpcolorpicker', function( event ) { event.stopPropagation(); }); /** * @summary Open or close the color picker depending on the class. * * @since 3.5 */ self.toggler.click( function(){ if ( self.toggler.hasClass( 'wp-picker-open' ) ) { self.close(); } else { self.open(); } }); /** * @summary Checks if value is empty when changing the color in the color picker. * * Checks if value is empty when changing the color in the color picker. * If so, the background color is cleared. * * @since 3.5.0 * * @param {Event} event The event that's being called. * * @returns {void} */ self.element.on( 'change', function( event ) { // Empty or Error = clear if ( $( this ).val() === '' || self.element.hasClass( 'iris-error' ) ) { if ( self.options.alpha ) { if ( _deprecated ) { self.toggler.removeAttr( 'style' ); } self.toggler.find( 'span.color-alpha' ).css( 'backgroundColor', '' ); } else { self.toggler.css( 'backgroundColor', '' ); } // fire clear callback if we have one if ( $.isFunction( self.options.clear ) ) self.options.clear.call( this, event ); } } ); /** * @summary Enables the user to clear or revert the color in the color picker. * * Enables the user to either clear the color in the color picker or revert back to the default color. * * @since 3.5.0 * * @param {Event} event The event that's being called. * * @returns {void} */ self.button.on( 'click', function( event ) { if ( $( this ).hasClass( 'wp-picker-clear' ) ) { self.element.val( '' ); if ( self.options.alpha ) { if ( _deprecated ) { self.toggler.removeAttr( 'style' ); } self.toggler.find( 'span.color-alpha' ).css( 'backgroundColor', '' ); } else { self.toggler.css( 'backgroundColor', '' ); } if ( $.isFunction( self.options.clear ) ) self.options.clear.call( this, event ); self.element.trigger( 'change' ); } else if ( $( this ).hasClass( 'wp-picker-default' ) ) { self.element.val( self.options.defaultColor ).change(); } }); }, }); /** * Overwrite iris */ $.widget( 'a8c.iris', $.a8c.iris, { _create: function() { this._super(); // Global option for check is mode rbga is enabled this.options.alpha = this.element.data( 'alpha' ) || false; // Is not input disabled if ( ! this.element.is( ':input' ) ) this.options.alpha = false; if ( typeof this.options.alpha !== 'undefined' && this.options.alpha ) { var self = this, el = self.element, _html = '<div class="iris-strip iris-slider iris-alpha-slider"><div class="iris-slider-offset iris-slider-offset-alpha"></div></div>', aContainer = $( _html ).appendTo( self.picker.find( '.iris-picker-inner' ) ), aSlider = aContainer.find( '.iris-slider-offset-alpha' ), controls = { aContainer : aContainer, aSlider : aSlider }; if ( typeof el.data( 'custom-width' ) !== 'undefined' ) { self.options.customWidth = parseInt( el.data( 'custom-width' ) ) || 0; } else { self.options.customWidth = 100; } // Set default width for input reset self.options.defaultWidth = el.width(); // Update width for input if ( self._color._alpha < 1 || self._color.toString().indexOf('rgb') != -1 ) el.width( parseInt( 88 ) ); // Push new controls $.each( controls, function( k, v ) { self.controls[k] = v; } ); // Change size strip and add margin for sliders self.controls.square.css( { 'margin-right': '0' } ); var emptyWidth = ( self.picker.width() - self.controls.square.width() - 20 ), stripsMargin = ( emptyWidth / 6 ), stripsWidth = ( ( emptyWidth / 2 ) - stripsMargin ); $.each( [ 'aContainer', 'strip' ], function( k, v ) { self.controls[v].width( stripsWidth ).css( { 'margin-left' : stripsMargin + 'px' } ); } ); // Add new slider self._initControls(); // For updated widget self._change(); } }, _initControls: function() { this._super(); if ( this.options.alpha ) { var self = this, controls = self.controls; controls.aSlider.slider({ orientation : 'vertical', min : 0, max : 100, step : 1, value : parseInt( self._color._alpha * 100 ), slide : function( event, ui ) { // Update alpha value self._color._alpha = parseFloat( ui.value / 100 ); self._change.apply( self, arguments ); } }); } }, _change: function() { this._super(); var self = this, el = self.element; if ( this.options.alpha ) { var controls = self.controls, alpha = parseInt( self._color._alpha * 100 ), color = self._color.toRgb(), gradient = [ 'rgb(' + color.r + ',' + color.g + ',' + color.b + ') 0%', 'rgba(' + color.r + ',' + color.g + ',' + color.b + ', 0) 100%' ], defaultWidth = self.options.defaultWidth, customWidth = self.options.customWidth, target = self.picker.closest( '.wp-picker-container' ).find( '.wp-color-result' ); // Generate background slider alpha, only for CSS3 old browser fuck!! :) controls.aContainer.css( { 'background' : 'linear-gradient(to bottom, ' + gradient.join( ', ' ) + '), url(' + image + ')' } ); if ( target.hasClass( 'wp-picker-open' ) ) { // Update alpha value controls.aSlider.slider( 'value', alpha ); /** * Disabled change opacity in default slider Saturation ( only is alpha enabled ) * and change input width for view all value */ if ( self._color._alpha < 1 ) { controls.strip.attr( 'style', controls.strip.attr( 'style' ).replace( /rgba\(([0-9]+,)(\s+)?([0-9]+,)(\s+)?([0-9]+)(,(\s+)?[0-9\.]+)\)/g, 'rgb($1$3$5)' ) ); el.width( parseInt( 88 ) ); } else { el.width( defaultWidth ); } } } var reset = el.data( 'reset-alpha' ) || false; if ( reset ) { self.picker.find( '.iris-palette-container' ).on( 'click.palette', '.iris-palette', function() { self._color._alpha = 1; self.active = 'external'; self._change(); } ); } el.trigger( 'change' ); }, _addInputListeners: function( input ) { var self = this, debounceTimeout = 100, callback = function( event ) { var color = new Color( input.val() ), val = input.val(); input.removeClass( 'iris-error' ); // we gave a bad color if ( color.error ) { // don't error on an empty input if ( val !== '' ) input.addClass( 'iris-error' ); } else { if ( color.toString() !== self._color.toString() ) { // let's not do this on keyup for hex shortcodes if ( ! ( event.type === 'keyup' && val.match( /^[0-9a-fA-F]{3}$/ ) ) ) self._setOption( 'color', color.toString() ); } } }; input.on( 'change', callback ).on( 'keyup', self._debounce( callback, debounceTimeout ) ); // If we initialized hidden, show on first focus. The rest is up to you. if ( self.options.hide ) { input.on( 'focus', function() { self.show(); } ); } } } ); }( jQuery ) ); // Auto Call plugin is class is color-picker jQuery( document ).ready( function( $ ) { $( '.color-picker' ).wpColorPicker(); } ); code/consultstreet-customize-slider-control.php 0000644 00000003750 15174424610 0016074 0 ustar 00 <?php /** * Customize Slider control class. * * @package consultstreet * * @see WP_Customize_Control * @access public */ /** * Class ConsultStreet_Customize_Slider_Control */ class ConsultStreet_Customize_Slider_Control extends ConsultStreet_Customize_Base_Control { /** * Customize control type. * * @access public * @var string */ public $type = 'consultstreet-slider'; /** * Refresh the parameters passed to the JavaScript via JSON. * * @see WP_Customize_Control::to_json() * @access public * @return void */ public function to_json() { parent::to_json(); if ( is_array( $this->json['default'] ) ) { foreach ( $this->json['default'] as $key => $value ) { $this->json['choices']['controls'][ $key ] = true; } } } /** * Renders the Underscore template for this control. * * @see WP_Customize_Control::print_template() * @access protected * @return void */ protected function content_template() { ?> <# if ( data.label ) { #> <span class="customize-control-title">{{ data.label }}</span> <# } #> <# if ( data.description ) { #> <span class="description customize-control-description">{{{ data.description }}}</span> <# } #> <div class="customize-control-content"> <div class="consultstreet-slider"> <div id="custom-handle" class="ui-slider-handle"></div> </div> <div class="consultstreet-slider-input"> <input {{{ data.inputAttrs }}} type="number" class="slider-input" value="{{ data.value['slider'] }}"/> <input type="text" value="{{ data.default['suffix'] }}" hidden> <span class="suffix">{{ data.default['suffix'] }}</span> <span class="slider-reset dashicons dashicons-image-rotate"><span class="screen-reader-text"><?php esc_html_e( 'Reset', 'consultstreet' ); ?></span></span> </div> </div> <?php } /** * Render content is still called, so be sure to override it with an empty function in your subclass as well. */ protected function render_content() { } } code/consultstreet-customize-sortable-control.php 0000644 00000003451 15174424610 0016423 0 ustar 00 <?php /** * Customize Sortable control class. * * @package consultstreet * * @see WP_Customize_Control * @access public */ /** * Class ConsultStreet_Customize_Sortable_Control */ class ConsultStreet_Customize_Sortable_Control extends ConsultStreet_Customize_Base_Control { /** * Customize control type. * * @access public * @var string */ public $type = 'consultstreet-sortable'; /** * Renders the Underscore template for this control. * * @see WP_Customize_Control::print_template() * @access protected * @return void */ protected function content_template() { ?> <label class='consultstreet-sortable'> <span class="customize-control-title"> {{{ data.label }}} </span> <# if ( data.description ) { #> <span class="description customize-control-description">{{{ data.description }}}</span> <# } #> <ul class="sortable"> <# _.each( data.value, function( choiceID ) { #> <li {{{ data.inputAttrs }}} class='consultstreet-sortable-item' data-value='{{ choiceID }}'> <i class='dashicons dashicons-menu'></i> <i class="dashicons dashicons-visibility visibility"></i> {{{ data.choices[ choiceID ] }}} </li> <# }); #> <# _.each( data.choices, function( choiceLabel, choiceID ) { #> <# if ( -1 === data.value.indexOf( choiceID ) ) { #> <li {{{ data.inputAttrs }}} class='consultstreet-sortable-item invisible' data-value='{{ choiceID }}'> <i class='dashicons dashicons-menu'></i> <i class="dashicons dashicons-visibility visibility"></i> {{{ data.choices[ choiceID ] }}} </li> <# } #> <# }); #> </ul> </label> <?php } /** * Render content is still called, so be sure to override it with an empty function in your subclass as well. */ protected function render_content() { } } code/consultstreet-customize-category-control.php 0000644 00000002717 15174424610 0016431 0 ustar 00 <?php /** * Customize Editor control class. * * @package consultstreet * * @see WP_Customize_Control * @access public */ if ( ! class_exists( 'WP_Customize_Control' ) ) return NULL; /** * Class ConsultStreet_Customize_Category_Control */ class ConsultStreet_Customize_Category_Control extends WP_Customize_Control { private $cats = false; public function __construct($manager, $id, $args = array(), $options = array()) { $this->cats = get_categories($options); parent::__construct( $manager, $id, $args ); } /** * Render the content of the category dropdown * * @return HTML */ public function render_content() { if(!empty($this->cats)) { ?> <label> <span class="customize-category-select-control"><?php echo esc_html( $this->label ); ?></span> <select multiple <?php $this->link(); ?>> <?php foreach ( $this->cats as $cat ) { printf('<option value="%s" %s>%s</option>', esc_html( $cat->term_id ), selected($this->value(), $cat->term_id, false), esc_html( $cat->name )); } ?> </select> </label> <?php } } } ?>