( function( $ ) {
jQuery(window).on("load", function() {
jQuery('html').addClass('background-colorpicker-ready');
});
wp.customize.controlConstructor['ast-background'] = wp.customize.Control.extend({
// When we're finished loading continue processing
ready: function() {
'use strict';
var control = this;
// Init the control.
control.initAstBgControl();
},
initAstBgControl: function() {
var control = this,
value = control.setting._value,
picker = control.container.find( '.ast-color-control' );
// Hide controls by default and show only when More Settings clicked.
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();
// Hide More Settings control only when image is not selected.
if ( _.isUndefined( value['background-image']) || '' === value['background-image']) {
control.container.find( '.more-settings' ).hide();
}
// Color.
picker.wpColorPicker({
change: function() {
if ( jQuery('html').hasClass('background-colorpicker-ready') ) {
setTimeout( function() {
control.saveValue( 'background-color', picker.val() );
}, 100 );
}
},
/**
* @param {Event} event - standard jQuery event, produced by "Clear"
* button.
*/
clear: function (event)
{
var element = jQuery(event.target).closest('.wp-picker-input-wrap').find('.wp-color-picker')[0];
if (element) {
control.saveValue( 'background-color', '' );
}
}
});
// 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() {
jQuery( this ).parent( '.buttonset' ).find( '.switch-input' ).removeAttr('checked');
jQuery( this ).attr( 'checked', 'checked' );
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() {
jQuery( this ).parent( '.buttonset' ).find( '.switch-input' ).removeAttr('checked');
jQuery( this ).attr( 'checked', 'checked' );
control.saveValue( 'background-attachment', jQuery( this ).val() );
});
// Background-Image.
control.container.on( 'click', '.background-image-upload-button, .thumbnail-image img', 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( '.more-settings' ).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( '' );
}
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();
control.container.find( '.more-settings' ).attr('data-direction', 'down');
control.container.find( '.more-settings' ).find('.message').html( astraCustomizerControlBackground.moreSettings );
control.container.find( '.more-settings' ).find('.icon').html( '↓' );
if ( preview.length ) {
preview.removeClass().addClass( 'placeholder' ).html( astraCustomizerControlBackground.placeholder );
}
if ( removeButton.length ) {
removeButton.hide();
}
});
control.container.on( 'click', '.more-settings', function( e ) {
// Hide unnecessary controls.
control.container.find( '.background-wrapper > .background-repeat' ).toggle();
control.container.find( '.background-wrapper > .background-position' ).toggle();
control.container.find( '.background-wrapper > .background-size' ).toggle();
control.container.find( '.background-wrapper > .background-attachment' ).toggle();
if( 'down' === $(this).attr( 'data-direction' ) )
{
$(this).attr('data-direction', 'up');
$(this).find('.message').html( astraCustomizerControlBackground.lessSettings );
$(this).find('.icon').html( '↑' );
} else {
$(this).attr('data-direction', 'down');
$(this).find('.message').html( astraCustomizerControlBackground.moreSettings );
$(this).find('.icon').html( '↓' );
}
});
},
/**
* 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 );
}
});
})(jQuery);
( function( $ ) {
/**
* File spacing.js
*
* Handles the spacing
*
* @package Astra
*/
wp.customize.controlConstructor['ast-border'] = wp.customize.Control.extend({
ready: function() {
'use strict';
var control = this,
value;
// Set the spacing container.
// this.container = control.container.find( 'ul.ast-border-wrapper' ).first();
// Save the value.
this.container.on( 'change keyup paste', 'input.ast-border-input', function() {
value = jQuery( this ).val();
// Update value on change.
control.updateValue();
});
},
/**
* Updates the spacing values
*/
updateValue: function() {
'use strict';
var control = this,
newValue = {
'top' : '',
'right' : '',
'bottom' : '',
'left' : '',
};
control.container.find( 'input.ast-border-desktop' ).each( function() {
var spacing_input = jQuery( this ),
item = spacing_input.data( 'id' ),
item_value = spacing_input.val();
newValue[item] = item_value;
});
control.setting.set( newValue );
},
});
jQuery( document ).ready( function( ) {
// Connected button
jQuery( '.ast-border-connected' ).on( 'click', function() {
// Remove connected class
jQuery(this).parent().parent( '.ast-border-wrapper' ).find( 'input' ).removeClass( 'connected' ).attr( 'data-element-connect', '' );
// Remove class
jQuery(this).parent( '.ast-border-input-item-link' ).removeClass( 'disconnected' );
} );
// Disconnected button
jQuery( '.ast-border-disconnected' ).on( 'click', function() {
// Set up variables
var elements = jQuery(this).data( 'element-connect' );
// Add connected class
jQuery(this).parent().parent( '.ast-border-wrapper' ).find( 'input' ).addClass( 'connected' ).attr( 'data-element-connect', elements );
// Add class
jQuery(this).parent( '.ast-border-input-item-link' ).addClass( 'disconnected' );
} );
// Values connected inputs
jQuery( '.ast-border-input-item' ).on( 'input', '.connected', function() {
var dataElement = jQuery(this).attr( 'data-element-connect' ),
currentFieldValue = jQuery( this ).val();
jQuery(this).parent().parent( '.ast-border-wrapper' ).find( '.connected[ data-element-connect="' + dataElement + '" ]' ).each( function( key, value ) {
jQuery(this).val( currentFieldValue ).change();
} );
} );
});
})(jQuery);
( function( $ ) {
/**
* File slider.js
*
* Handles Slider control
*
* @package Astra
*/
jQuery(window).on("load", function() {
jQuery('html').addClass('colorpicker-ready');
});
wp.customize.controlConstructor['ast-color'] = wp.customize.Control.extend({
ready: function() {
'use strict';
var control = this,
value,
thisInput,
inputDefault,
changeAction;
this.container.find('.ast-color-picker-alpha' ).wpColorPicker({
/**
* @param {Event} event - standard jQuery event, produced by whichever
* control was changed.
* @param {Object} ui - standard jQuery UI object, with a color member
* containing a Color.js object.
*/
change: function (event, ui) {
var element = event.target;
var color = ui.color.toString();
if ( jQuery('html').hasClass('colorpicker-ready') ) {
control.setting.set( color );
}
},
/**
* @param {Event} event - standard jQuery event, produced by "Clear"
* button.
*/
clear: function (event) {
var element = jQuery(event.target).closest('.wp-picker-input-wrap').find('.wp-color-picker')[0];
var color = '';
if (element) {
// Add your code here
control.setting.set( color );
}
}
});
}
});
})(jQuery);
( function( $ ) {
/**
* File link.js
*
* Handles the link
*
* @package Astra
*/
wp.customize.controlConstructor['ast-link'] = wp.customize.Control.extend({
ready: function() {
'use strict';
var control = this;
var data = jQuery( '.customize-link-control-data' ).data('value');
// Save the value.
this.container.on( 'change keyup', '.ast-link-input', function(e) {
e.preventDefault();
value = jQuery( this ).val();
data.url = value;
jQuery('.customize-link-control-data').attr('data-value', JSON.stringify( data )).trigger( 'change' );
// Update value on change.
control.setting.set( data );
});
// Save the value.
this.container.on( 'change click', '.ast-link-open-in-new-tab', function() {
value = jQuery( this ).is(":checked");
data.new_tab = value;
jQuery('.customize-link-control-data').attr('data-value', JSON.stringify( data )).trigger( 'change' );
// Update value on change.
control.setting.set( data );
});
// Save the value.
this.container.on( 'change keyup', '.ast-link-relationship', function(e) {
e.preventDefault();
value = jQuery( this ).val();
data.link_rel = value;
jQuery('.customize-link-control-data').attr('data-value', JSON.stringify( data )).trigger( 'change' );
// Update value on change.
control.setting.set( data );
});
},
});
})(jQuery);
/**
* File spacing.js
*
* Handles the spacing
*
* @package Astra
*/
wp.customize.controlConstructor['ast-customizer-link'] = wp.customize.Control.extend({
ready: function () {
'use strict';
// Add event listener for click action.
this.container.on('click', '.customizer-link', function (e) {
e.preventDefault();
var section;
var linked = this.getAttribute('data-customizer-linked');
var linkType = this.getAttribute('data-ast-customizer-link-type');
switch (linkType) {
case 'section':
section = wp.customize.section(linked);
section.expand();
break;
case 'control':
wp.customize.control(linked).focus();
break;
default:
break;
}
});
},
});
/**
* File radio-image.js
*
* Handles toggling the radio images button
*
* @package Astra
*/
wp.customize.controlConstructor['ast-radio-image'] = wp.customize.Control.extend({
ready: function() {
'use strict';
var control = this;
// Change the value.
this.container.on( 'click', 'input', function() {
control.setting.set( jQuery( this ).val() );
});
}
});
( function( $ ) {
/**
* File responsive.js
*
* Handles the responsive
*
* @package Astra
*/
wp.customize.controlConstructor['ast-responsive'] = wp.customize.Control.extend({
// When we're finished loading continue processing.
ready: function() {
'use strict';
var control = this,
value;
control.astResponsiveInit();
/**
* Save on change / keyup / paste
*/
this.container.on( 'change keyup paste', 'input.ast-responsive-input, select.ast-responsive-select', function() {
value = jQuery( this ).val();
// Update value on change.
control.updateValue();
});
/**
* Refresh preview frame on blur
*/
this.container.on( 'blur', 'input', function() {
value = jQuery( this ).val() || '';
if ( value == '' ) {
wp.customize.previewer.refresh();
}
});
jQuery( '.customize-control-ast-responsive .input-wrapper input.' + 'desktop' + ', .customize-control .ast-responsive-btns > li.' + 'desktop' ).addClass( 'active' );
},
/**
* Updates the sorting list
*/
updateValue: function() {
'use strict';
var control = this,
newValue = {};
// Set the spacing container.
control.responsiveContainer = control.container.find( '.ast-responsive-wrapper' ).first();
control.responsiveContainer.find( 'input.ast-responsive-input' ).each( function() {
var responsive_input = jQuery( this ),
item = responsive_input.data( 'id' ),
item_value = responsive_input.val();
newValue[item] = item_value;
});
control.responsiveContainer.find( 'select.ast-responsive-select' ).each( function() {
var responsive_input = jQuery( this ),
item = responsive_input.data( 'id' ),
item_value = responsive_input.val();
newValue[item] = item_value;
});
control.setting.set( newValue );
},
astResponsiveInit : function() {
'use strict';
this.container.find( '.ast-responsive-btns button' ).on( 'click', function( event ) {
var device = jQuery(this).attr('data-device');
if( 'desktop' == device ) {
device = 'tablet';
} else if( 'tablet' == device ) {
device = 'mobile';
} else {
device = 'desktop';
}
jQuery( '.wp-full-overlay-footer .devices button[data-device="' + device + '"]' ).trigger( 'click' );
});
},
});
jQuery(' .wp-full-overlay-footer .devices button ').on('click', function() {
var device = jQuery(this).attr('data-device');
jQuery( '.customize-control-ast-responsive .input-wrapper input, .customize-control .ast-responsive-btns > li' ).removeClass( 'active' );
jQuery( '.customize-control-ast-responsive .input-wrapper input.' + device + ', .customize-control .ast-responsive-btns > li.' + device ).addClass( 'active' );
});
})(jQuery);
( function( $ ) {
jQuery(window).on("load", function() {
jQuery('html').addClass('responsive-background-color-ready');
});
/**
* File responsive-color.js
*
* Handles the responsive color
*
* @package Astra
*/
wp.customize.controlConstructor['ast-responsive-color'] = wp.customize.Control.extend({
// When we're finished loading continue processing
ready: function() {
'use strict';
var control = this;
// Init the control.
control.initAstBgControl();
},
initAstBgControl: function() {
var control = this,
value = control.setting._value,
picker = control.container.find( '.ast-responsive-color' );
// Color.
picker.wpColorPicker({
change: function(event, ui) {
if ( jQuery('html').hasClass('responsive-background-color-ready') ) {
var stored = control.setting.get();
var device = jQuery( this ).data( 'id' );
var newValue = {
'desktop' : stored['desktop'],
'tablet' : stored['tablet'],
'mobile' : stored['mobile'],
};
if ( 'desktop' === device ) {
newValue['desktop'] = ui.color.toString();
}
if ( 'tablet' === device ) {
newValue['tablet'] = ui.color.toString();
}
if ( 'mobile' === device ) {
newValue['mobile'] = ui.color.toString();
}
control.setting.set( newValue );
}
},
/**
* @param {Event} event - standard jQuery event, produced by "Clear"
* button.
*/
clear: function (event) {
var element = jQuery(event.target).closest('.wp-picker-input-wrap').find('.wp-color-picker')[0],
device = jQuery( this ).closest('.wp-picker-input-wrap').find('.wp-color-picker').data( 'id' );
var stored = control.setting.get();
var newValue = {
'desktop' : stored['desktop'],
'tablet' : stored['tablet'],
'mobile' : stored['mobile'],
};
if ( element ) {
if ( 'desktop' === device ) {
newValue['desktop'] = '';
}
if ( 'tablet' === device ) {
newValue['tablet'] = '';
}
if ( 'mobile' === device ) {
newValue['mobile'] = '';
}
control.setting.set( newValue );
}
}
});
this.container.find( '.ast-responsive-btns button' ).on( 'click', function( event ) {
var device = jQuery(this).attr('data-device');
if( 'desktop' == device ) {
device = 'tablet';
} else if( 'tablet' == device ) {
device = 'mobile';
} else {
device = 'desktop';
}
jQuery( '.wp-full-overlay-footer .devices button[data-device="' + device + '"]' ).trigger( 'click' );
});
jQuery( '.customize-control-ast-responsive-color .customize-control-content .ast-responsive-color.desktop' ).parents( '.wp-picker-container' ).addClass( 'active' );
}
});
jQuery('.wp-full-overlay-footer .devices button').on('click', function() {
var device = jQuery(this).attr('data-device');
jQuery( '.customize-control-ast-responsive-color .customize-control-content .wp-picker-container' ).removeClass( 'active' );
jQuery( '.customize-control-ast-responsive-color .customize-control-content .ast-responsive-color.' + device ).parents( '.wp-picker-container' ).addClass( 'active' );
});
})(jQuery);
jQuery(window).on("load", function() {
jQuery('html').addClass('responsive-background-img-ready');
});
wp.customize.controlConstructor['ast-responsive-background'] = wp.customize.Control.extend({
// When we're finished loading continue processing
ready: function() {
'use strict';
var control = this;
// Init the control.
control.initAstBgControl();
control.astResponsiveInit();
},
initAstBgControl: function() {
var control = this,
value = control.setting._value,
picker = control.container.find( '.ast-responsive-bg-color-control' );
// Hide unnecessary controls if the value doesn't have an image.
if ( _.isUndefined( value['desktop']['background-image']) || '' === value['desktop']['background-image']) {
control.container.find( '.background-wrapper > .background-container.desktop > .background-repeat' ).hide();
control.container.find( '.background-wrapper > .background-container.desktop > .background-position' ).hide();
control.container.find( '.background-wrapper > .background-container.desktop > .background-size' ).hide();
control.container.find( '.background-wrapper > .background-container.desktop > .background-attachment' ).hide();
}
if ( _.isUndefined( value['tablet']['background-image']) || '' === value['tablet']['background-image']) {
control.container.find( '.background-wrapper > .background-container.tablet > .background-repeat' ).hide();
control.container.find( '.background-wrapper > .background-container.tablet > .background-position' ).hide();
control.container.find( '.background-wrapper > .background-container.tablet > .background-size' ).hide();
control.container.find( '.background-wrapper > .background-container.tablet > .background-attachment' ).hide();
}
if ( _.isUndefined( value['mobile']['background-image']) || '' === value['mobile']['background-image']) {
control.container.find( '.background-wrapper > .background-container.mobile > .background-repeat' ).hide();
control.container.find( '.background-wrapper > .background-container.mobile > .background-position' ).hide();
control.container.find( '.background-wrapper > .background-container.mobile > .background-size' ).hide();
control.container.find( '.background-wrapper > .background-container.mobile > .background-attachment' ).hide();
}
// Color.
picker.wpColorPicker({
change: function(event, ui) {
var device = jQuery( this ).data( 'id' );
if ( jQuery('html').hasClass('responsive-background-img-ready') ) {
control.saveValue( device, 'background-color', ui.color.toString() );
}
},
/**
* @param {Event} event - standard jQuery event, produced by "Clear"
* button.
*/
clear: function (event)
{
var element = jQuery(event.target).closest('.wp-picker-input-wrap').find('.wp-color-picker')[0],
responsive_input = jQuery( this ),
screen = responsive_input.closest('.wp-picker-input-wrap').find('.wp-color-picker').data( 'id' );
if (element) {
control.saveValue( screen, 'background-color', '' );
}
}
});
// Background-Repeat.
control.container.on( 'change', '.background-repeat select', function() {
var responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' ),
item_value = responsive_input.val();
control.saveValue( screen, 'background-repeat', item_value );
});
// Background-Size.
control.container.on( 'change click', '.background-size input', function() {
var responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' ),
item_value = responsive_input.val();
responsive_input.parent( '.buttonset' ).find( '.switch-input' ).removeAttr('checked');
responsive_input.attr( 'checked', 'checked' );
control.saveValue( screen, 'background-size', item_value );
});
// Background-Position.
control.container.on( 'change', '.background-position select', function() {
var responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' ),
item_value = responsive_input.val();
control.saveValue( screen, 'background-position', item_value );
});
// Background-Attachment.
control.container.on( 'change click', '.background-attachment input', function() {
var responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' ),
item_value = responsive_input.val();
responsive_input.parent( '.buttonset' ).find( '.switch-input' ).removeAttr('checked');
responsive_input.attr( 'checked', 'checked' );
control.saveValue( screen, 'background-attachment', item_value );
});
// Background-Image.
control.container.on( 'click', '.background-image-upload-button', function( e ) {
var responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' );
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( screen, 'background-image', imageUrl );
preview = control.container.find( '.background-container.'+screen+' .placeholder, .background-container.'+screen+' .thumbnail' );
removeButton = control.container.find( '.background-container.'+screen+' .background-image-upload-remove-button' );
if ( preview.length ) {
preview.removeClass().addClass( 'thumbnail thumbnail-image' ).html( '
' );
}
if ( removeButton.length ) {
removeButton.show();
}
});
e.preventDefault();
});
control.container.on( 'click', '.background-image-upload-remove-button', function( e ) {
var preview,
removeButton,
responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' );
e.preventDefault();
control.saveValue( screen, 'background-image', '' );
preview = control.container.find( '.background-container.'+ screen +' .placeholder, .background-container.'+ screen +' .thumbnail' );
removeButton = control.container.find( '.background-container.'+ screen +' .background-image-upload-remove-button' );
// Hide unnecessary controls.
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-repeat' ).hide();
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-position' ).hide();
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-size' ).hide();
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-attachment' ).hide();
control.container.find( '.background-container.'+ screen +' .more-settings' ).attr('data-direction', 'down');
control.container.find( '.background-container.'+ screen +' .more-settings' ).find('.message').html( astraCustomizerControlBackground.moreSettings );
control.container.find( '.background-container.'+ screen +' .more-settings' ).find('.icon').html( '↓' );
if ( preview.length ) {
preview.removeClass().addClass( 'placeholder' ).html( astraCustomizerControlBackground.placeholder );
}
if ( removeButton.length ) {
removeButton.hide();
}
});
control.container.on( 'click', '.more-settings', function( e ) {
var responsive_input = jQuery( this ),
screen = responsive_input.data( 'id' );
// Hide unnecessary controls.
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-repeat' ).toggle();
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-position' ).toggle();
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-size' ).toggle();
control.container.find( '.background-wrapper > .background-container.'+ screen +' > .background-attachment' ).toggle();
if( 'down' === jQuery(this).attr( 'data-direction' ) )
{
jQuery(this).attr('data-direction', 'up');
jQuery(this).find('.message').html( astraCustomizerControlBackground.lessSettings )
jQuery(this).find('.icon').html( '↑' );
} else {
jQuery(this).attr('data-direction', 'down');
jQuery(this).find('.message').html( astraCustomizerControlBackground.moreSettings )
jQuery(this).find('.icon').html( '↓' );
}
});
},
astResponsiveInit : function() {
'use strict';
this.container.find( '.ast-responsive-btns button' ).on( 'click', function( event ) {
var device = jQuery(this).attr('data-device');
if( 'desktop' == device ) {
device = 'tablet';
} else if( 'tablet' == device ) {
device = 'mobile';
} else {
device = 'desktop';
}
jQuery( '.wp-full-overlay-footer .devices button[data-device="' + device + '"]' ).trigger( 'click' );
});
},
/**
* Saves the value.
*/
saveValue: function( screen, property, value ) {
var control = this,
input = jQuery( '#customize-control-' + control.id.replace( '[', '-' ).replace( ']', '' ) + ' .responsive-background-hidden-value' ),
val = control.setting._value;
val[ screen ][ property ] = value;
jQuery( input ).attr( 'value', JSON.stringify( val ) ).trigger( 'change' );
control.setting.set( val );
}
});
jQuery(' .wp-full-overlay-footer .devices button ').on('click', function() {
var device = jQuery(this).attr('data-device');
jQuery( '.customize-control-ast-responsive-background .background-container, .customize-control .ast-responsive-btns > li' ).removeClass( 'active' );
jQuery( '.customize-control-ast-responsive-background .background-container.' + device + ', .customize-control .ast-responsive-btns > li.' + device ).addClass( 'active' );
});
( function( $ ) {
/**
* File slider.js
*
* Handles Slider control
*
* @package Astra
*/
wp.customize.controlConstructor['ast-responsive-slider'] = wp.customize.Control.extend({
ready: function() {
'use strict';
var control = this,
value,
thisInput,
inputDefault,
changeAction;
control.astResponsiveInit();
// Update the text value.
this.container.on( 'input change', 'input[type=range]', function() {
var value = jQuery( this ).val(),
input_number = jQuery( this ).closest( '.input-field-wrapper' ).find( '.ast-responsive-range-value-input' );
input_number.val( value );
input_number.trigger( 'change' );
});
// Handle the reset button.
this.container.on('click', '.ast-responsive-slider-reset', function() {
var wrapper = jQuery( this ).parent().find('.input-field-wrapper.active'),
input_range = wrapper.find( 'input[type=range]' ),
input_number = wrapper.find( '.ast-responsive-range-value-input' ),
default_value = input_range.data( 'reset_value' );
input_range.val( default_value );
input_number.val( default_value );
input_number.trigger( 'change' );
});
// Save changes.
this.container.on( 'input change', 'input[type=number]', function() {
var value = jQuery( this ).val();
jQuery( this ).closest( '.input-field-wrapper' ).find( 'input[type=range]' ).val( value );
control.updateValue();
});
},
/**
* Updates the sorting list
*/
updateValue: function() {
'use strict';
var control = this,
newValue = {};
// Set the spacing container.
control.responsiveContainer = control.container.find( '.wrapper' ).first();
control.responsiveContainer.find( '.ast-responsive-range-value-input' ).each( function() {
var responsive_input = jQuery( this ),
item = responsive_input.data( 'id' ),
item_value = responsive_input.val();
newValue[item] = item_value;
});
control.setting.set( newValue );
},
astResponsiveInit : function() {
this.container.on( 'click', '.ast-responsive-slider-btns button', function( event ) {
event.preventDefault();
var device = jQuery(this).attr('data-device');
if( 'desktop' == device ) {
device = 'tablet';
} else if( 'tablet' == device ) {
device = 'mobile';
} else {
device = 'desktop';
}
jQuery( '.wp-full-overlay-footer .devices button[data-device="' + device + '"]' ).trigger( 'click' );
});
},
});
jQuery(' .wp-full-overlay-footer .devices button ').on('click', function() {
var device = jQuery(this).attr('data-device');
jQuery( '.customize-control-ast-responsive-slider .input-field-wrapper, .customize-control .ast-responsive-slider-btns > li' ).removeClass( 'active' );
jQuery( '.customize-control-ast-responsive-slider .input-field-wrapper.' + device + ', .customize-control .ast-responsive-slider-btns > li.' + device ).addClass( 'active' );
});
})(jQuery);
( function( $ ) {
/**
* File spacing.js
*
* Handles the spacing
*
* @package Astra
*/
wp.customize.controlConstructor['ast-responsive-spacing'] = wp.customize.Control.extend({
ready: function() {
'use strict';
var control = this,
value;
control.astResponsiveInit();
// Set the spacing container.
// this.container = control.container.find( 'ul.ast-spacing-wrapper' ).first();
// Save the value.
this.container.on( 'change keyup paste', 'input.ast-spacing-input', function() {
value = jQuery( this ).val();
// Update value on change.
control.updateValue();
});
},
/**
* Updates the spacing values
*/
updateValue: function() {
'use strict';
var control = this,
newValue = {
'desktop' : {},
'tablet' : {},
'mobile' : {},
'desktop-unit' : 'px',
'tablet-unit' : 'px',
'mobile-unit' : 'px',
};
control.container.find( 'input.ast-spacing-desktop' ).each( function() {
var spacing_input = jQuery( this ),
item = spacing_input.data( 'id' ),
item_value = spacing_input.val();
newValue['desktop'][item] = item_value;
});
control.container.find( 'input.ast-spacing-tablet' ).each( function() {
var spacing_input = jQuery( this ),
item = spacing_input.data( 'id' ),
item_value = spacing_input.val();
newValue['tablet'][item] = item_value;
});
control.container.find( 'input.ast-spacing-mobile' ).each( function() {
var spacing_input = jQuery( this ),
item = spacing_input.data( 'id' ),
item_value = spacing_input.val();
newValue['mobile'][item] = item_value;
});
control.container.find('.ast-spacing-unit-wrapper .ast-spacing-unit-input').each( function() {
var spacing_unit = jQuery( this ),
device = spacing_unit.attr('data-device'),
device_val = spacing_unit.val(),
name = device + '-unit';
newValue[ name ] = device_val;
});
control.setting.set( newValue );
},
/**
* Set the responsive devices fields
*/
astResponsiveInit : function() {
'use strict';
var control = this;
control.container.find( '.ast-spacing-responsive-btns button' ).on( 'click', function( event ) {
var device = jQuery(this).attr('data-device');
if( 'desktop' == device ) {
device = 'tablet';
} else if( 'tablet' == device ) {
device = 'mobile';
} else {
device = 'desktop';
}
jQuery( '.wp-full-overlay-footer .devices button[data-device="' + device + '"]' ).trigger( 'click' );
});
// Unit click
control.container.on( 'click', '.ast-spacing-responsive-units .single-unit', function() {
var $this = jQuery(this);
if ( $this.hasClass('active') ) {
return false;
}
var unit_value = $this.attr('data-unit'),
device = jQuery('.wp-full-overlay-footer .devices button.active').attr('data-device');
$this.siblings().removeClass('active');
$this.addClass('active');
control.container.find('.ast-spacing-unit-wrapper .ast-spacing-' + device + '-unit').val( unit_value );
// Update value on change.
control.updateValue();
});
},
});
jQuery( document ).ready( function( ) {
// Connected button
jQuery( '.ast-spacing-connected' ).on( 'click', function() {
// Remove connected class
jQuery(this).parent().parent( '.ast-spacing-wrapper' ).find( 'input' ).removeClass( 'connected' ).attr( 'data-element-connect', '' );
// Remove class
jQuery(this).parent( '.ast-spacing-input-item-link' ).removeClass( 'disconnected' );
} );
// Disconnected button
jQuery( '.ast-spacing-disconnected' ).on( 'click', function() {
// Set up variables
var elements = jQuery(this).data( 'element-connect' );
// Add connected class
jQuery(this).parent().parent( '.ast-spacing-wrapper' ).find( 'input' ).addClass( 'connected' ).attr( 'data-element-connect', elements );
// Add class
jQuery(this).parent( '.ast-spacing-input-item-link' ).addClass( 'disconnected' );
} );
// Values connected inputs
jQuery( '.ast-spacing-input-item' ).on( 'input', '.connected', function() {
var dataElement = jQuery(this).attr( 'data-element-connect' ),
currentFieldValue = jQuery( this ).val();
jQuery(this).parent().parent( '.ast-spacing-wrapper' ).find( '.connected[ data-element-connect="' + dataElement + '" ]' ).each( function( key, value ) {
jQuery(this).val( currentFieldValue ).change();
} );
} );
});
jQuery('.wp-full-overlay-footer .devices button ').on('click', function() {
var device = jQuery(this).attr('data-device');
jQuery( '.customize-control-ast-responsive-spacing .input-wrapper .ast-spacing-wrapper, .customize-control .ast-spacing-responsive-btns > li' ).removeClass( 'active' );
jQuery( '.customize-control-ast-responsive-spacing .input-wrapper .ast-spacing-wrapper.' + device + ', .customize-control .ast-spacing-responsive-btns > li.' + device ).addClass( 'active' );
});
})(jQuery);
( function( $ ) {
/**
* JS to manage the sticky heading of an open section on scroll up.
*/
jQuery( document ).ready(function() {
var last_scroll_top = 0;
var parentSection = jQuery( '.wp-full-overlay-sidebar-content' );
var browser = navigator.userAgent.toLowerCase();
if ( ! ( browser.indexOf( 'firefox' ) > -1 ) ) {
var parent_width_remove = 6;
} else {
var parent_width_remove = 16;
}
jQuery('#customize-controls .wp-full-overlay-sidebar-content .control-section').on( 'scroll', function (event) {
var $this = jQuery(this);
// Run sticky js for only open section.
if ( $this.hasClass( 'open' ) ) {
var section_title = $this.find( '.customize-section-title' );
var scroll_top = $this.scrollTop();
if ( scroll_top > last_scroll_top ) {
// On scroll down, remove sticky section title.
section_title.removeClass( 'maybe-sticky' ).removeClass( 'is-in-view' ).removeClass( 'is-sticky' );
$this.css( 'padding-top', '' );
} else {
// On scroll up, add sticky section title.
var parent_width = $this.outerWidth();
section_title.addClass( 'maybe-sticky' ).addClass( 'is-in-view' ).addClass( 'is-sticky' ).width( parent_width - parent_width_remove ).css( 'top', parentSection.css( 'top' ) );
if ( ! ( browser.indexOf( 'firefox' ) > -1 ) ) {
$this.css( 'padding-top', section_title.height() );
}
if( scroll_top === 0 ) {
// Remove sticky section heading when scrolled to the top.
section_title.removeClass( 'maybe-sticky' ).removeClass( 'is-in-view' ).removeClass( 'is-sticky' );
$this.css( 'padding-top', '' );
}
}
last_scroll_top = scroll_top;
}
});
});
wp.customize.controlConstructor['ast-settings-group'] = wp.customize.Control.extend({
ready : function() {
'use strict';
var control = this,
value = control.setting._value;
control.registerToggleEvents();
this.container.on( 'ast_settings_changed', control.onOptionChange );
},
registerToggleEvents: function() {
var control = this;
/* Close popup when click outside anywhere outside of popup */
$( '.wp-full-overlay-sidebar-content, .wp-picker-container' ).click( function( e ) {
if ( ! $( e.target ).closest( '.ast-field-settings-modal' ).length ) {
$( '.ast-adv-toggle-icon.open' ).trigger( 'click' );
}
});
control.container.on( 'click', '.ast-toggle-desc-wrap .ast-adv-toggle-icon', function( e ) {
e.preventDefault();
e.stopPropagation();
var $this = jQuery(this);
var parent_wrap = $this.closest( '.customize-control-ast-settings-group' );
var is_loaded = parent_wrap.find( '.ast-field-settings-modal' ).data('loaded');
var parent_section = parent_wrap.parents('.control-section');
if( $this.hasClass('open') ) {
parent_wrap.find( '.ast-field-settings-modal' ).hide();
} else {
/* Close popup when another popup is clicked to open */
var get_open_popup = parent_section.find('.ast-adv-toggle-icon.open');
if( get_open_popup.length > 0 ) {
get_open_popup.trigger('click');
}
if( is_loaded ) {
parent_wrap.find( '.ast-field-settings-modal' ).show();
} else {
var fields = control.params.ast_fields;
var $modal_wrap = $( astra.customizer.group_modal_tmpl );
parent_wrap.find( '.ast-field-settings-wrap' ).append( $modal_wrap );
parent_wrap.find( '.ast-fields-wrap' ).attr( 'data-control', control.params.name );
control.ast_render_field( parent_wrap, fields, control );
parent_wrap.find( '.ast-field-settings-modal' ).show();
device = jQuery("#customize-footer-actions .active").attr('data-device');
if( 'mobile' == device ) {
jQuery('.ast-responsive-btns .mobile, .ast-responsive-slider-btns .mobile').addClass('active');
jQuery('.ast-responsive-btns .preview-mobile, .ast-responsive-slider-btns .preview-mobile').addClass('active');
} else if( 'tablet' == device ) {
jQuery('.ast-responsive-btns .tablet, .ast-responsive-slider-btns .tablet').addClass('active');
jQuery('.ast-responsive-btns .preview-tablet, .ast-responsive-slider-btns .preview-tablet').addClass('active');
} else {
jQuery('.ast-responsive-btns .desktop, .ast-responsive-slider-btns .desktop').addClass('active');
jQuery('.ast-responsive-btns .preview-desktop, .ast-responsive-slider-btns .preview-desktop').addClass('active');
}
}
}
$this.toggleClass('open');
});
control.container.on( "click", ".ast-toggle-desc-wrap > .customizer-text", function( e ) {
e.preventDefault();
e.stopPropagation();
jQuery(this).find( '.ast-adv-toggle-icon' ).trigger('click');
});
},
ast_render_field: function( wrap, fields, control_elem ) {
var control = this;
var ast_field_wrap = wrap.find( '.ast-fields-wrap' );
var fields_html = '';
var control_types = [];
var field_values = control.isJsonString( control_elem.params.value ) ? JSON.parse( control_elem.params.value ) : {};
if( 'undefined' != typeof fields.tabs ) {
var clean_param_name = control_elem.params.name.replace( '[', '-' ),
clean_param_name = clean_param_name.replace( ']', '' );
fields_html += '