rename all files named mt- to sad-
This commit is contained in:
222
assets/js/sad-customizer-controls.js
Normal file
222
assets/js/sad-customizer-controls.js
Normal file
@ -0,0 +1,222 @@
|
||||
( function( api ) {
|
||||
|
||||
api.sectionConstructor['sad-upsell'] = api.Section.extend( {
|
||||
|
||||
// No events for this type of section.
|
||||
attachEvents: function () {},
|
||||
|
||||
// Always make the section active.
|
||||
isContextuallyActive: function () {
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
|
||||
} )( wp.customize );
|
||||
|
||||
wp.customize.controlConstructor['sad-toggle'] = wp.customize.Control.extend({
|
||||
ready: function(){
|
||||
'use strict';
|
||||
|
||||
var control = this,
|
||||
checkboxValue = control.setting._value;
|
||||
|
||||
// Toggle checkbox
|
||||
// Save the value
|
||||
this.container.on( 'change', 'input', function() {
|
||||
checkboxValue = ( jQuery( this ).is( ':checked' ) ) ? true : false;
|
||||
control.setting.set( checkboxValue );
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
|
||||
"use strict";
|
||||
/**
|
||||
* Function for repeater field
|
||||
*/
|
||||
function sophia_after_dark_refresh_repeater_values(){
|
||||
$(".sad-repeater-field-control-wrap").each(function(){
|
||||
|
||||
var values = [];
|
||||
var $this = $(this);
|
||||
|
||||
$this.find(".sad-repeater-field-control").each(function(){
|
||||
var valueToPush = {};
|
||||
|
||||
$(this).find('[data-name]').each(function(){
|
||||
|
||||
var dataName = $(this).attr('data-name');
|
||||
var dataValue = $(this).val();
|
||||
valueToPush[dataName] = dataValue;
|
||||
});
|
||||
|
||||
values.push(valueToPush);
|
||||
});
|
||||
|
||||
$this.next('.sad-repeater-collector').val(JSON.stringify(values)).trigger('change');
|
||||
});
|
||||
}
|
||||
|
||||
$('#customize-theme-controls').on('click','.sad-repeater-field-title',function(){
|
||||
$(this).next().slideToggle();
|
||||
$(this).closest('.sad-repeater-field-control').toggleClass('expanded');
|
||||
});
|
||||
|
||||
$('#customize-theme-controls').on('click', '.sad-repeater-field-close', function(){
|
||||
$(this).closest('.sad-repeater-fields').slideUp();;
|
||||
$(this).closest('.sad-repeater-field-control').toggleClass('expanded');
|
||||
});
|
||||
|
||||
$("body").on("click",'.sad-repeater-add-control-field', function(){
|
||||
|
||||
var fLimit = $(this).parent().find('.field-limit').val();
|
||||
var fCount = $(this).parent().find('.field-count').val();
|
||||
if( fCount < fLimit ) {
|
||||
fCount++;
|
||||
$(this).parent().find('.field-count').val(fCount);
|
||||
} else {
|
||||
$(this).before('<span class="sad-limit-msg"><em>Only '+fLimit+' repeater field will be permitted.</em></span>');
|
||||
return;
|
||||
}
|
||||
|
||||
var $this = $(this).parent();
|
||||
if(typeof $this != 'undefined') {
|
||||
|
||||
var field = $this.find(".sad-repeater-field-control:first").clone();
|
||||
if(typeof field != 'undefined'){
|
||||
|
||||
field.find("input[type='text'][data-name]").each(function(){
|
||||
var defaultValue = $(this).attr('data-default');
|
||||
$(this).val(defaultValue);
|
||||
});
|
||||
|
||||
field.find("textarea[data-name]").each(function(){
|
||||
var defaultValue = $(this).attr('data-default');
|
||||
$(this).val(defaultValue);
|
||||
});
|
||||
|
||||
field.find("select[data-name]").each(function(){
|
||||
var defaultValue = $(this).attr('data-default');
|
||||
$(this).val(defaultValue);
|
||||
});
|
||||
|
||||
field.find(".attachment-media-view").each(function(){
|
||||
var defaultValue = $(this).find('input[data-name]').attr('data-default');
|
||||
$(this).find('input[data-name]').val(defaultValue);
|
||||
if(defaultValue){
|
||||
$(this).find(".thumbnail-image").html('<img src="'+defaultValue+'"/>').prev('.placeholder').addClass('hidden');
|
||||
}else{
|
||||
$(this).find(".thumbnail-image").html('').prev('.placeholder').removeClass('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
field.find(".sad-repeater-icon-list").each(function(){
|
||||
var defaultValue = $(this).next('input[data-name]').attr('data-default');
|
||||
$(this).next('input[data-name]').val(defaultValue);
|
||||
$(this).prev('.sad-repeater-selected-icon').children('i').attr('class','').addClass(defaultValue);
|
||||
|
||||
$(this).find('li').each(function(){
|
||||
var icon_class = $(this).find('i').attr('class');
|
||||
if(defaultValue == icon_class ){
|
||||
$(this).addClass('icon-active');
|
||||
}else{
|
||||
$(this).removeClass('icon-active');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
field.find('.sad-repeater-fields').show();
|
||||
$this.find('.sad-repeater-field-control-wrap').append(field);
|
||||
field.addClass('expanded').find('.sad-repeater-fields').show();
|
||||
$('.accordion-section-content').animate({ scrollTop: $this.height() }, 1000);
|
||||
sophia_after_dark_refresh_repeater_values();
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#customize-theme-controls").on("click", ".sad-repeater-field-remove",function(){
|
||||
if( typeof $(this).parent() != 'undefined'){
|
||||
$(this).closest('.sad-repeater-field-control').slideUp('normal', function(){
|
||||
$(this).remove();
|
||||
sophia_after_dark_refresh_repeater_values();
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#customize-theme-controls").on('keyup change', '[data-name]',function(){
|
||||
sophia_after_dark_refresh_repeater_values();
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* Drag and drop to change order
|
||||
*/
|
||||
$(".sad-repeater-field-control-wrap").sortable({
|
||||
orientation: "vertical",
|
||||
update: function( event, ui ) {
|
||||
sophia_after_dark_refresh_repeater_values();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Image upload
|
||||
*/
|
||||
var mtFrame;
|
||||
|
||||
//Add image
|
||||
$('.customize-control-sad-repeater').on( 'click', '.sad-upload-button', function( event ){
|
||||
event.preventDefault();
|
||||
|
||||
var imgContainer = $(this).closest('.sad-fields-wrap').find( '.thumbnail-image'),
|
||||
placeholder = $(this).closest('.sad-fields-wrap').find( '.placeholder'),
|
||||
imgIdInput = $(this).siblings('.upload-id');
|
||||
|
||||
mtFrame = wp.media({
|
||||
title: 'Select or Upload Image',
|
||||
button: {
|
||||
text: 'Use Image'
|
||||
},
|
||||
multiple: false // Set to true to allow multiple files to be selected
|
||||
});
|
||||
|
||||
mtFrame.on( 'select', function() {
|
||||
var attachment = frame.state().get('selection').first().toJSON();
|
||||
imgContainer.html( '<img src="'+attachment.url+'" style="max-width:100%;"/>' );
|
||||
placeholder.addClass('hidden');
|
||||
imgIdInput.val( attachment.url ).trigger('change');
|
||||
});
|
||||
|
||||
mtFrame.open();
|
||||
});
|
||||
|
||||
// DELETE IMAGE LINK
|
||||
$('.customize-control-sad-repeater').on( 'click', '.sad-delete-button', function( event ){
|
||||
event.preventDefault();
|
||||
var imgContainer = $(this).closest('.sad-fields-wrap').find( '.thumbnail-image'),
|
||||
placeholder = $(this).closest('.sad-fields-wrap').find( '.placeholder'),
|
||||
imgIdInput = $(this).siblings('.upload-id');
|
||||
imgContainer.find('img').remove();
|
||||
placeholder.removeClass('hidden');
|
||||
imgIdInput.val( '' ).trigger('change');
|
||||
});
|
||||
|
||||
/**
|
||||
* Repeater icon selector
|
||||
*/
|
||||
$('body').on('click', '.sad-repeater-icon-list li', function(){
|
||||
var icon_class = $(this).find('i').attr('class');
|
||||
$(this).addClass('icon-active').siblings().removeClass('icon-active');
|
||||
$(this).parent('.sad-repeater-icon-list').prev('.sad-repeater-selected-icon').children('i').attr('class','').addClass(icon_class);
|
||||
$(this).parent('.sad-repeater-icon-list').next('input').val(icon_class).trigger('change');
|
||||
sophia_after_dark_refresh_repeater_values();
|
||||
});
|
||||
|
||||
$('body').on('click', '.sad-repeater-selected-icon', function(){
|
||||
$(this).next().slideToggle();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user