From 3bf310f7be326f8d52cb22efd53ecdbe06607501 Mon Sep 17 00:00:00 2001 From: Aristeides Stathopoulos Date: Wed, 5 Jul 2017 21:54:47 +0300 Subject: [PATCH] fooling around --- .../class-kirki-modules-postmessage.php | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/modules/postmessage/class-kirki-modules-postmessage.php b/modules/postmessage/class-kirki-modules-postmessage.php index 4c4e02b63..59bd507d4 100644 --- a/modules/postmessage/class-kirki-modules-postmessage.php +++ b/modules/postmessage/class-kirki-modules-postmessage.php @@ -92,11 +92,9 @@ public function postmessage() { */ protected function script( $args ) { - $script = 'wp.customize(\'' . $args['settings'] . '\',function(value){value.bind(function(newval){'; - // append unique style tag if not exist - // The style ID. $style_id = 'kirki-postmessage-' . str_replace( array( '[', ']' ), '', $args['settings'] ); - $script .= 'if(null===document.getElementById(\'' . $style_id . '\')||\'undefined\'===typeof document.getElementById(\'' . $style_id . '\')){jQuery(\'head\').append(\'\');}'; + $script = "wp.customize('{$args['settings']}',function(value){value.bind(function(newval){"; + $script .= "if(null===document.getElementById('{$style_id}')||'undefined'===typeof document.getElementById('{$style_id}')){jQuery('head').append('');}"; // Add anything we need before the main script. $script .= $this->before_script( $args ); @@ -122,7 +120,7 @@ protected function script( $args ) { $js_var['element'] = implode( ',', $js_var['element'] ); } // Replace single quotes with double quotes to avoid issues with the compiled JS. - $js_var['element'] = str_replace( '\'', '"', $js_var['element'] ); + $js_var['element'] = str_replace( "'", '"', $js_var['element'] ); } if ( isset( $js_var['function'] ) && 'html' === $js_var['function'] ) { $script .= $this->script_html_var( $js_var ); @@ -142,7 +140,7 @@ protected function script( $args ) { $combo_extra_script .= $script_array['script']; $combo_css_script .= ( 'css' !== $combo_css_script ) ? $script_array['css'] : ''; } - $text = ( 'css' === $combo_css_script ) ? 'css' : '\'' . $combo_css_script . '\''; + $text = ( 'css' === $combo_css_script ) ? 'css' : "'{$combo_css_script}'"; $script .= $combo_extra_script; $script .= "var cssContent={$text};"; @@ -200,7 +198,7 @@ protected function script_var( $args ) { // Tweak to add url() for background-images. if ( 'background-image' === $args['property'] && ( ! isset( $args['value_pattern'] ) || false === strpos( $args['value_pattern'], 'gradient' ) ) ) { - $script .= 'if(-1===' . $value_key . '.indexOf(\'url(\')){' . $value_key . '=\'url("\'+' . $value_key . '+\'")\';}'; + $script .= "if(-1==={$value_key}.indexOf('url(')){{$value_key}='url(\"'+{$value_key}+'\")';}"; } // Apply prefix. @@ -208,7 +206,7 @@ protected function script_var( $args ) { if ( '' !== $args['prefix'] ) { $value = $args['prefix'] . '+' . $value_key; } - $css = $args['element'] . '{' . $args['property'] . ':\'+' . $value . '+\'' . $args['units'] . $args['suffix'] . ';}'; + $css = "{$args['element']}{{$args['property']}:'+{$value}+'{$args['units']}{$args['suffix']};}"; if ( isset( $args['media_query'] ) ) { $css = $args['media_query'] . '{' . $css . '}'; } @@ -227,7 +225,7 @@ protected function script_var( $args ) { */ protected function script_var_array( $args ) { - $script = ( 0 === $args['index_key'] ) ? 'css=\'\';' : ''; + $script = ( 0 === $args['index_key'] ) ? "css='';" : ''; $property_script = ''; // Define choice. @@ -251,39 +249,39 @@ protected function script_var_array( $args ) { // Tweak to add url() for background-images. if ( '' === $choice || 'background-image' === $choice ) { - $script .= 'if(\'background-image\'===\'' . $args['property'] . '\'||\'background-image\'===subKey){'; - $script .= 'if(-1===subValue.indexOf(\'url(\')){subValue=\'url("\'+subValue+\'")\';}'; + $script .= "if('background-image'==='{$args['property']}'||'background-image'===subKey){"; + $script .= "if(-1===subValue.indexOf('url(')){subValue='url(\"'+subValue+'\")';}"; $script .= '}'; } // Apply prefix. $value = $value_key; if ( '' !== $args['prefix'] ) { - $value = '\'' . $args['prefix'] . '\'+subValue'; + $value = "'{$args['prefix']}'+subValue"; } // Mostly used for padding, margin & position properties. - $direction_script = 'if(_.contains([\'top\',\'bottom\',\'left\',\'right\'],subKey)){'; - $direction_script .= 'css+=\'' . $args['element'] . '{' . $args['property'] . '-\'+subKey+\':\'+subValue+\'' . $args['units'] . $args['suffix'] . ';}\';}'; + $direction_script = "if(_.contains(['top','bottom','left','right'],subKey)){"; + $direction_script .= "css+='{$args['element']}{{$args['property']}-'+subKey+':'+subValue+'{$args['units']}{$args['suffix']};}';}"; // Allows us to apply this just for a specific choice in the array of the values. if ( '' !== $choice ) { $choice_is_direction = ( false !== strpos( $choice, 'top' ) || false !== strpos( $choice, 'bottom' ) || false !== strpos( $choice, 'left' ) || false !== strpos( $choice, 'right' ) ); - $script .= 'if(\'' . $choice . '\'===subKey){'; + $script .= "if('{$choice}'===subKey){"; $script .= ( $choice_is_direction ) ? $direction_script . 'else{' : ''; - $script .= 'css+=\'' . $args['element'] . '{' . $args['property'] . ':\'+subValue+\';}\';'; + $script .= "css+='{$args['element']}{{$args['property']}:'+subValue+';}';"; $script .= ( $choice_is_direction ) ? '}' : ''; $script .= '}'; } else { $script .= $direction_script . 'else{'; // This is where most object-based fields will go. - $script .= 'css+=\'' . $args['element'] . '{\'+subKey+\':\'+subValue+\'' . $args['units'] . $args['suffix'] . ';}\';'; + $script .= "css+='{$args['element']}{'+subKey+':'+subValue+'{$args['units']}{$args['suffix']};}';"; $script .= '}'; } $script .= '});'; if ( isset( $args['media_query'] ) ) { - $script .= 'css=\'' . $args['media_query'] . '{\'+css+\'}\';'; + $script .= "css='{$args['media_query']}{'+css+'}';"; } return array( @@ -307,7 +305,7 @@ protected function script_var_typography( $args, $field ) { // Load the font using WenFontloader. // This is a bit ugly because wp_add_inline_script doesn't allow adding