public function wp_footer()
 {
     $script = $this->generate_script();
     if ('' != $script) {
         echo Kirki_Scripts_Registry::prepare($script);
     }
 }
 public function customize_controls_print_scripts()
 {
     $script = $this->generate_script();
     if ('' != $script) {
         echo Kirki_Scripts_Registry::prepare($script);
     }
 }
 public function wp_footer()
 {
     global $wp_customize;
     // Early exit if we're not in the customizer
     if (!isset($wp_customize)) {
         return;
     }
     // Get an array of all the fields
     $fields = Kirki::fields()->get_all();
     $script = '';
     // Parse the fields and create the script.
     foreach ($fields as $field) {
         if (isset($field['transport']) && !is_null($field['js_vars']) && 'postMessage' == $field['transport']) {
             foreach ($field['js_vars'] as $js_vars) {
                 $script .= 'wp.customize( \'' . $field['settings'] . '\', function( value ) {';
                 $script .= 'value.bind( function( newval ) {';
                 if ('html' == $js_vars['function']) {
                     $script .= '$( \'' . esc_js($js_vars["element"]) . '\' ).html( newval );';
                 } elseif ('css' == $js_vars['function']) {
                     $script .= '$(\'' . esc_js($js_vars["element"]) . '\').css(\'' . esc_js($js_vars["property"]) . '\', newval );';
                 }
                 $script .= '}); });';
             }
         }
     }
     if ('' != $script) {
         echo Kirki_Scripts_Registry::prepare($script);
     }
 }
 public function wp_footer()
 {
     $code = $this->generate_script();
     if (empty($code)) {
         return;
     }
     if ('' != $code[0]) {
         echo Kirki_Scripts_Registry::prepare($code[0]);
     }
     echo implode('', $code[1]);
 }
 /**
  * If we've specified an image to be used as logo,
  * replace the default theme description with a div that will include our logo.
  */
 public function customize_controls_print_scripts()
 {
     $options = Kirki::config()->get_all();
     $script = '';
     if ('' != $options['logo_image'] || '' != $options['description']) {
         if ('' != $options['logo_image']) {
             $script .= '$( \'div#customize-info .preview-notice\' ).replaceWith( \'<img src="' . $options['logo_image'] . '">\' );';
         }
         if ('' != $options['description']) {
             $script .= '$( \'div#customize-info .accordion-section-content\' ).replaceWith( \'<div class="accordion-section-content"><div class="theme-description">' . $options['description'] . '</div></div>\' );';
         }
     }
     if ('' != $script) {
         echo Kirki_Scripts_Registry::prepare($script);
     }
 }
 /**
  * Add the script to the footer
  */
 function customize_controls_print_footer_scripts()
 {
     $fields = Kirki::fields()->get_all();
     $scripts = array();
     foreach ($fields as $field) {
         if ('number' == $field['type']) {
             $scripts[] = '$( "#customize-control-' . $field['settings'] . ' input[type=\'number\']").stepper();';
         }
     }
     // No need to echo anything if the script is empty
     if (empty($scripts)) {
         return;
     }
     // Make sure we don't add any duplicates
     $scripts = array_unique($scripts);
     // Convert array to string
     $script = implode('', $scripts);
     echo Kirki_Scripts_Registry::prepare($script);
 }
 /**
  * Add the help bubble
  */
 function customize_controls_print_footer_scripts()
 {
     $fields = Kirki::fields()->get_all();
     $scripts = array();
     $script = '';
     foreach ($fields as $field) {
         if (!empty($field['help'])) {
             $bubble_content = $field['help'];
             $content = "<a href='#' class='tooltip hint--left' data-hint='" . strip_tags(esc_html($bubble_content)) . "'><span class='dashicons dashicons-info'></span></a>";
             $scripts[] = '$( "' . $content . '" ).prependTo( "#customize-control-' . $field['settings'] . '" );';
         }
     }
     // No need to echo anything if the script is empty
     if (empty($scripts)) {
         return;
     }
     // Make sure we don't add any duplicates
     $scripts = array_unique($scripts);
     // Convert array to string
     $script = implode('', $scripts);
     echo Kirki_Scripts_Registry::prepare($script);
 }
 /**
  * Add the required script.
  */
 function customize_controls_print_footer_scripts()
 {
     // Get an array of all our fields
     $fields = Kirki::fields()->get_all();
     // Get the config options
     $config = Kirki::config()->get_all();
     // Early exit if no controls are defined
     if (empty($fields)) {
         return;
     }
     $script = '';
     foreach ($fields as $field) {
         $required = isset($field['required']) ? $field['required'] : false;
         if ($required) {
             $show = false;
             foreach ($required as $dependency) {
                 // Find the type of the dependency control
                 if ('option' == $config['options_type'] && '' != $config['option_name']) {
                     $dependency['setting'] = $config['option_name'] . '[' . $dependency['setting'] . ']';
                 }
                 $type = $fields[$dependency['setting']]['type'];
                 // If "operator" is not set then set it to "=="
                 if (!isset($dependency['operator'])) {
                     $dependency['operator'] = '==';
                 }
                 $dependency['operator'] = esc_js($dependency['operator']);
                 // Set the control type
                 $type = 'dropdown-pages' == $type ? 'select' : $type;
                 $type = 'radio-image' == $type ? 'radio' : $type;
                 $type = 'radio-buttonset' == $type ? 'radio' : $type;
                 $type = 'toggle' == $type ? 'checkbox' : $type;
                 $type = 'switch' == $type ? 'checkbox' : $type;
                 // Set the controller used in the script
                 $controller = '#customize-control-' . $fields[$dependency['setting']]['id'] . ' input';
                 $common_controller = '';
                 // Se the controller for select-type controls
                 if ('select' == $type) {
                     $controller = '#customize-control-' . $fields[$dependency['setting']]['id'] . ' select';
                 } elseif ('radio' == $type) {
                     $controller = '#customize-control-' . $fields[$dependency['setting']]['id'] . ' input[value="' . $dependency['value'] . '"]';
                     $common_controller = '#customize-control-' . $fields[$dependency['setting']]['id'] . ' input';
                 }
                 // The target element
                 $target = '#customize-control-' . $field['id'];
                 // if this is a background control then make sure we target all sub-controls
                 if ('background' == $field['type']) {
                     $target = '#customize-control-' . $control['settings'] . '_color, ';
                     $target .= '#customize-control-' . $control['settings'] . '_image, ';
                     $target .= '#customize-control-' . $control['settings'] . '_repeat, ';
                     $target .= '#customize-control-' . $control['settings'] . '_size, ';
                     $target .= '#customize-control-' . $control['settings'] . '_position, ';
                     $target .= '#customize-control-' . $control['settings'] . '_attach';
                 }
                 // If no operator has been defined, fallback to '=='
                 if (!isset($dependency['operator'])) {
                     $dependency['operator'] = '==';
                 }
                 $action_1 = '.show()';
                 $action_2 = '.hide()';
                 // Allow checking both checked and unchecked checkboxes
                 if ('checkbox' == $type) {
                     if (0 == $dependency['value'] && '==' == $dependency['operator']) {
                         $action_1 = '.hide()';
                         $action_2 = '.show()';
                         $show = true;
                     }
                     if (1 == $dependency['value'] && '!=' == $dependency['operator']) {
                         $action_1 = '.hide()';
                         $action_2 = '.show()';
                     }
                 }
                 // Get the initial status
                 $value = kirki_get_option($dependency['setting']);
                 switch ($dependency['operator']) {
                     case '==':
                         $show = $dependency['value'] == $value ? true : $show;
                         break;
                     case '!=':
                         $show = $dependency['value'] != $value ? true : $show;
                         break;
                     case '>=':
                         $show = $dependency['value'] >= $value ? true : $show;
                         break;
                     case '<=':
                         $show = $dependency['value'] <= $value ? true : $show;
                         break;
                     case '>':
                         $show = $dependency['value'] > $value ? true : $show;
                         break;
                     case '<':
                         $show = $dependency['value'] < $value ? true : $show;
                         break;
                     default:
                         $show = $dependency['value'] == $value ? true : $show;
                 }
                 // if initial status is hidden then hide the control
                 if (false == $show) {
                     $script .= '$("' . $target . '").hide();';
                 }
                 // Create the actual script
                 $script .= "\$('" . ('radio' != $type ? $controller : $common_controller) . "').";
                 $script .= 'checkbox' == $type ? 'click' : 'change';
                 $script .= '(function(){';
                 $script .= "if (\$('" . $controller . "').";
                 $script .= 'select' != $type ? 'is(":checked") ) {' : 'val() ' . $dependency['operator'] . ' "' . $dependency['value'] . '") {';
                 $script .= "\$('" . $target . "')" . $action_1 . ';';
                 $script .= '} else {';
                 $script .= "\$('" . $target . "')" . $action_2 . ';';
                 $script .= '}});';
                 $script .= 'checkbox' != $type ? "\$('" . $controller . "')" . '.trigger("change");' : '';
             }
         }
     }
     // If there's a script then echo it wrapped.
     if (!empty($script)) {
         echo Kirki_Scripts_Registry::prepare($script);
     }
 }