D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
proc
/
self
/
cwd
/
wp-content
/
themes
/
aeen
/
assets
/
js
/
Filename :
customizer.js
back
Copy
jQuery( document ).ready(function($) { "use strict"; /** * Sortable Repeater Custom Control * * @since Roofix 1.0 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ // Update the values for all our input fields and initialise the sortable repeater $('.sortable_repeater_control').each(function() { // If there is an existing customizer value, populate our rows var defaultValuesArray = $(this).find('.customize-control-sortable-repeater').val().split(','); var numRepeaterItems = defaultValuesArray.length; if(numRepeaterItems > 0) { // Add the first item to our existing input field $(this).find('.repeater-input').val(defaultValuesArray[0]); // Create a new row for each new value if(numRepeaterItems > 1) { var i; for (i = 1; i < numRepeaterItems; ++i) { rtthemeAppendRow($(this), defaultValuesArray[i]); } } } }); // Make our Repeater fields sortable $(this).find('.sortable').sortable({ update: function(event, ui) { rtthemeGetAllInputs($(this).parent()); } }); // Remove item starting from it's parent element $('.sortable').on('click', '.customize-control-sortable-repeater-delete', function(event) { event.preventDefault(); var numItems = $(this).parent().parent().find('.repeater').length; if(numItems > 1) { $(this).parent().slideUp('fast', function() { var parentContainer = $(this).parent().parent(); $(this).remove(); rtthemeGetAllInputs(parentContainer); }) } else { $(this).parent().find('.repeater-input').val(''); rtthemeGetAllInputs($(this).parent().parent().parent()); } }); // Add new item $('.customize-control-sortable-repeater-add').click(function(event) { event.preventDefault(); rtthemeAppendRow($(this).parent()); rtthemeGetAllInputs($(this).parent()); }); // Refresh our hidden field if any fields change $('.sortable').change(function() { rtthemeGetAllInputs($(this).parent()); }) // Add https:// to the start of the URL if it doesn't have it $('.sortable').on('blur', '.repeater-input', function() { var url = $(this); var val = url.val(); if(val && !val.match(/^.+:\/\/.*/)) { // Important! Make sure to trigger change event so Customizer knows it has to save the field url.val('https://' + val).trigger('change'); } }); // Append a new row to our list of elements function rtthemeAppendRow($element, defaultValue = '') { var newRow = '<div class="repeater" style="display:none"><input type="text" value="' + defaultValue + '" class="repeater-input" placeholder="https://" /><span class="dashicons dashicons-sort"></span><a class="customize-control-sortable-repeater-delete" href="#"><span class="dashicons dashicons-no-alt"></span></a></div>'; $element.find('.sortable').append(newRow); $element.find('.sortable').find('.repeater:last').slideDown('slow', function(){ $(this).find('input').focus(); }); } // Get the values from the repeater input fields and add to our hidden field function rtthemeGetAllInputs($element) { var inputValues = $element.find('.repeater-input').map(function() { return $(this).val(); }).toArray(); // Add all the values from our repeater fields to the hidden field (which is the one that actually gets saved) $element.find('.customize-control-sortable-repeater').val(inputValues); // Important! Make sure to trigger change event so Customizer knows it has to save the field $element.find('.customize-control-sortable-repeater').trigger('change'); } /** * Slider Custom Control * * @since Roofix 1.0 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ // Set our slider defaults and initialise the slider $('.slider-custom-control').each(function(){ var sliderValue = $(this).find('.customize-control-slider-value').val(); var newSlider = $(this).find('.slider'); var sliderMinValue = parseFloat(newSlider.attr('slider-min-value')); var sliderMaxValue = parseFloat(newSlider.attr('slider-max-value')); var sliderStepValue = parseFloat(newSlider.attr('slider-step-value')); newSlider.slider({ value: sliderValue, min: sliderMinValue, max: sliderMaxValue, step: sliderStepValue, change: function(e,ui){ // Important! When slider stops moving make sure to trigger change event so Customizer knows it has to save the field $(this).parent().find('.customize-control-slider-value').trigger('change'); } }); }); // Change the value of the input field as the slider is moved $('.slider').on('slide', function(event, ui) { $(this).parent().find('.customize-control-slider-value').val(ui.value); }); // Reset slider and input field back to the default value $('.slider-reset').on('click', function() { var resetValue = $(this).attr('slider-reset-value'); $(this).parent().find('.customize-control-slider-value').val(resetValue); $(this).parent().find('.slider').slider('value', resetValue); }); // Update slider if the input field loses focus as it's most likely changed $('.customize-control-slider-value').blur(function() { var resetValue = $(this).val(); var slider = $(this).parent().find('.slider'); var sliderMinValue = parseInt(slider.attr('slider-min-value')); var sliderMaxValue = parseInt(slider.attr('slider-max-value')); // Make sure our manual input value doesn't exceed the minimum & maxmium values if(resetValue < sliderMinValue) { resetValue = sliderMinValue; $(this).val(resetValue); } if(resetValue > sliderMaxValue) { resetValue = sliderMaxValue; $(this).val(resetValue); } $(this).parent().find('.slider').slider('value', resetValue); }); /** * Single Accordion Custom Control * * @since Roofix 1.0 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ $('.single-accordion-toggle').click(function() { var $accordionToggle = $(this); $(this).parent().find('.single-accordion').slideToggle('slow', function() { $accordionToggle.toggleClass('single-accordion-toggle-rotate', $(this).is(':visible')); }); }); /** * Image Check Box Custom Control * * @since Roofix 1.0 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ $('.multi-image-checkbox').on('change', function () { getAllCheckboxes($(this).parent().parent()); }); // Get the values from the checkboxes and add to our hidden field function getAllCheckboxes($element) { var inputValues = $element.find('.multi-image-checkbox').map(function() { if( $(this).is(':checked') ) { return $(this).val(); // } else { // return ''; } }).toArray(); // Important! Make sure to trigger change event so Customizer knows it has to save the field $element.find('.customize-control-multi-image-checkbox').val(inputValues).trigger('change'); } /** * Dropdown Select2 Custom Control * * @since Roofix 1.4 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ $('.customize-control-dropdown-select2').each(function(){ $('.customize-control-select2').select2({ allowClear: true }); }); $(".customize-control-select2").on("change", function() { var select2Val = $(this).val(); $(this).parent().find('.customize-control-dropdown-select2').val(select2Val).trigger('change'); }); /** * Googe Font Select Custom Control * * @since Roofix 1.0 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ $('.google-fonts-list').each(function (i, obj) { if (!$(obj).hasClass('select2-hidden-accessible')) { $(obj).select2(); } }); $('.google-fonts-list').on('change', function() { var elementRegularWeight = $(this).parent().parent().find('.google-fonts-regularweight-style'); var elementItalicWeight = $(this).parent().parent().find('.google-fonts-italicweight-style'); var elementBoldWeight = $(this).parent().parent().find('.google-fonts-boldweight-style'); var selectedFont = $(this).val(); var customizerControlName = $(this).attr('control-name'); var elementItalicWeightCount = 0; var elementBoldWeightCount = 0; // Clear Weight/Style dropdowns elementRegularWeight.empty(); elementItalicWeight.empty(); elementBoldWeight.empty(); // Make sure Italic & Bold dropdowns are enabled elementItalicWeight.prop('disabled', false); elementBoldWeight.prop('disabled', false); // Get the Google Fonts control object var bodyfontcontrol = _wpCustomizeSettings.controls[customizerControlName]; // Find the index of the selected font var indexes = $.map(bodyfontcontrol.rtthemefontslist, function(obj, index) { if(obj.family === selectedFont) { return index; } }); var index = indexes[0]; // For the selected Google font show the available weight/style variants $.each(bodyfontcontrol.rtthemefontslist[index].variants, function(val, text) { elementRegularWeight.append( $('<option></option>').val(text).html(text) ); if (text.indexOf("italic") >= 0) { elementItalicWeight.append( $('<option></option>').val(text).html(text) ); elementItalicWeightCount++; } else { elementBoldWeight.append( $('<option></option>').val(text).html(text) ); elementBoldWeightCount++; } }); if(elementItalicWeightCount == 0) { elementItalicWeight.append( $('<option></option>').val('').html('Not Available for this font') ); elementItalicWeight.prop('disabled', 'disabled'); } if(elementBoldWeightCount == 0) { elementBoldWeight.append( $('<option></option>').val('').html('Not Available for this font') ); elementBoldWeight.prop('disabled', 'disabled'); } // Update the font category based on the selected font $(this).parent().parent().find('.google-fonts-category').val(bodyfontcontrol.rtthemefontslist[index].category); rtthemeGetAllSelects($(this).parent().parent()); }); $('.google_fonts_select_control select').on('change', function() { rtthemeGetAllSelects($(this).parent().parent()); }); function rtthemeGetAllSelects($element) { var selectedFont = { font: $element.find('.google-fonts-list').val(), regularweight: $element.find('.google-fonts-regularweight-style').val(), italicweight: $element.find('.google-fonts-italicweight-style').val(), boldweight: $element.find('.google-fonts-boldweight-style').val(), category: $element.find('.google-fonts-category').val() }; // Important! Make sure to trigger change event so Customizer knows it has to save the field $element.find('.customize-control-google-font-selection').val(JSON.stringify(selectedFont)).trigger('change'); } /** * TinyMCE Custom Control * * @since Roofix 1.0 * * @author Anthony Hortin <http://maddisondesigns.com> * @license http://www.gnu.org/licenses/gpl-2.0.html * @link https://github.com/maddisondesigns */ $('.customize-control-tinymce-editor').each(function(){ // Get the toolbar strings that were passed from the PHP Class var tinyMCEToolbar1String = _wpCustomizeSettings.controls[$(this).attr('id')].rtthemetinymcetoolbar1; var tinyMCEToolbar2String = _wpCustomizeSettings.controls[$(this).attr('id')].rtthemetinymcetoolbar2; wp.editor.initialize( $(this).attr('id'), { tinymce: { wpautop: true, toolbar1: tinyMCEToolbar1String, toolbar2: tinyMCEToolbar2String }, quicktags: true }); }); $(document).on( 'tinymce-editor-init', function( event, editor ) { editor.on('change', function(e) { tinyMCE.triggerSave(); $('#'+editor.id).trigger('change'); }); }); // Gallery Control $(window).load(function() { var begin_attachment_string = $("#images-input").val(); var begin_attachment_array = begin_attachment_string.split(","); for(var i = 0; i < begin_attachment_array.length; i++){ if(begin_attachment_array[i] != ""){ $(".images").append( "<li class='image-list'><img src='"+begin_attachment_array[i]+"'></li>" ); } } $(".button-secondary.upload").click(function(){ var custom_uploader = wp.media.frames.file_frame = wp.media({ multiple: true }); custom_uploader.on('select', function() { var selection = custom_uploader.state().get('selection'); var attachments = []; selection.map( function( attachment ) { attachment = attachment.toJSON(); $(".images").append( "<li class='image-list'><img src='"+attachment.url+"'></li>" ); attachments.push(attachment.url); // }); var attachment_string = attachments.join() + "," + $('#images-input').val(); $('#images-input').val(attachment_string).trigger('change'); }); custom_uploader.open(); }); $(".images").click(function(){ var img_src = $(event.target).find("img").attr('src'); $(event.target).closest("li").remove(); var attachment_string = $('#images-input').val(); attachment_string = attachment_string.replace(img_src+",", ""); $('#images-input').val(attachment_string).trigger('change'); }); }); });