Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Remade customizer to extend GeneratePress #97

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6d43b16
Merge branch 'master' into customizer-remake
marekdedic Sep 6, 2019
dd7268c
Merge branch 'master' into customizer-remake
marekdedic Sep 7, 2019
7698329
Merge branch 'master' into customizer-remake
marekdedic Sep 20, 2019
a8e7007
(Almost) remade body background to be GeneratePress-compatible
marekdedic Sep 22, 2019
511444d
Copied over default values
marekdedic Sep 22, 2019
82aa9da
Remade body background-repeat to be GeneratePress-compatible
marekdedic Sep 23, 2019
07bff7b
Remade body background-size to be GeneratePress-compatible
marekdedic Sep 23, 2019
582b373
Fixed lint issues
marekdedic Sep 23, 2019
2cc6c1c
Merge branch 'master' into customizer-remake
marekdedic Sep 23, 2019
0d5b296
Remade body background-attachment to be GeneratePress-compatible
marekdedic Sep 23, 2019
2ed534c
Remade body background to be GeneratePress-compatible
marekdedic Sep 23, 2019
db661d3
Added Background_Image_Customize_Control
marekdedic Sep 25, 2019
ca6da3e
Split body background config
marekdedic Sep 25, 2019
8922900
Remade header background to be GeneratePress-compatible
marekdedic Sep 27, 2019
a9a0f75
Fixed default value for body background image
marekdedic Sep 27, 2019
8955186
Remade header foreground to be GeneratePress-compatible
marekdedic Sep 27, 2019
a488e09
Not adding sections if added by GP
marekdedic Sep 27, 2019
ae95517
Remade header grass image to be GeneratePress-compatible
marekdedic Sep 27, 2019
e038a59
Removed Kirki from background class
marekdedic Sep 27, 2019
3b2563c
Enabled multiple outputs for webpack
marekdedic Sep 28, 2019
563b90f
Added preset control
marekdedic Sep 29, 2019
11047a2
Removed old code
marekdedic Sep 29, 2019
b749459
Functional preset changing
marekdedic Sep 29, 2019
9124e53
Added body color selection to presets
marekdedic Sep 29, 2019
7de8295
Styled the preset chooser
marekdedic Sep 29, 2019
14e067d
Added the Customizer_Category class to reuse code better
marekdedic Sep 29, 2019
5391574
Remade border radius to be GeneratePress-compatible
marekdedic Sep 29, 2019
d356bf2
Setting border radius in new presets
marekdedic Sep 30, 2019
2d871a6
Added dummy color configuration
marekdedic Sep 30, 2019
7f36a29
Added primary navigation background color control
marekdedic Sep 30, 2019
4344cc7
Controling menu background & color through GP-compatible functions
marekdedic Oct 1, 2019
23cebe9
Added color sanitization
marekdedic Oct 4, 2019
6dcc033
Merge branch 'master' into customizer-remake
marekdedic Oct 11, 2019
f63e3f3
Merge branch 'master' into customizer-remake
marekdedic Oct 22, 2019
38c5a78
Fixed a missing switch case
marekdedic Oct 23, 2019
f3bd995
Lint fixes
marekdedic Oct 23, 2019
17b97ff
Converted content font
marekdedic Oct 23, 2019
92c49a7
Removed SCSS overrides to GP
marekdedic Oct 23, 2019
720447b
Converted menu font
marekdedic Oct 24, 2019
6168886
Fixed lint issues
marekdedic Oct 24, 2019
7c6270d
Converted H1 font
marekdedic Oct 24, 2019
281474c
Converted H2 font
marekdedic Oct 24, 2019
1149b06
Fixed GP Premium error
marekdedic Oct 24, 2019
96a9c36
Merge branch 'master' into customizer-remake
marekdedic Nov 12, 2019
e68c7d9
Switched [] to array()
marekdedic Nov 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class Generate_Range_Slider_Control {
public function __construct( $manager, $id, $args = [] ) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class Generate_Typography_Customize_Control {
public function __construct( $manager, $id, $args = [] ) {
}
}
4 changes: 4 additions & 0 deletions .phan/stubs/GeneratePress/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

function generatepress_is_module_active( $module, $definition ) {
}
18 changes: 18 additions & 0 deletions .phan/stubs/WordPress/class-wp-control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class WP_Customize_Control {
public $json;
public $settings;

public function __construct( $a, $b, $c ) {
}

public function get_link( $a ) {
}

public function to_json() {
}

public function value( $a ) {
}
}
6 changes: 6 additions & 0 deletions .phan/stubs/WordPress/class-wp-customize-color-control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class WP_Customize_Color_Control {
public function __construct( $manager, $id, $args = [] ) {
}
}
6 changes: 6 additions & 0 deletions .phan/stubs/WordPress/class-wp-customize-image-control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class WP_Customize_Image_Control {
public function __construct( $manager, $id, $args = [] ) {
}
}
18 changes: 18 additions & 0 deletions .phan/stubs/WordPress/class-wp-customize-manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class WP_Customize_manager {
public function add_control( $id, $args = [] ) {
}

public function add_panel( $id, $args = [] ) {
}

public function add_section( $id, $args = [] ) {
}

public function add_setting( $id, $args = [] ) {
}

public function register_control_type( $a ) {
}
}
34 changes: 33 additions & 1 deletion .phan/stubs/WordPress/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
* @package skaut-google-drive-gallery
*/

function __($a, $b) {
return '';
}

function absint( $a ) {
return 0;
}

function add_action( $a, $b, $c = '' ) {
}

Expand Down Expand Up @@ -34,6 +42,10 @@ function esc_html__( $a, $b ) {
return '';
}

function esc_url( $a ) {
return '';
}

function get_option( $a, $b ) {
switch ( wp_rand( 0, 2 ) ) {
case 0:
Expand Down Expand Up @@ -85,6 +97,10 @@ function remove_action( $a, $b, $c = '' ) {
return false;
}

function sanitize_text_field( $a ) {
return '';
}

function switch_theme( $a ) {
}

Expand All @@ -101,11 +117,27 @@ function trailingslashit( $a ) {
return '';
}

function wp_add_inline_style( $a, $b ) {
}

function wp_enqueue_script( $a, $b, $c, $d, $e ) {
}

function wp_enqueue_style( $a, $b, $c, $d ) {
function wp_enqueue_style( $a, $b = '', $c = [], $d = false ) {
}

function wp_localize_script( $a, $b, $c ) {
}

/**
* @return array
*/
function wp_parse_args( $a, $b ) {
return [];
}

function wp_rand( $a, $b ) {
}

function wp_register_style( $a, $b, $c, $d ) {
}
6 changes: 6 additions & 0 deletions src/js/admin/colors_live_preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

jQuery( 'document' ).ready( function( $ ) {
generatepress_colors_live_update( 'h1_color', 'h1', 'color', '', 'text_color' );
generatepress_colors_live_update( 'h2_color', 'h2', 'color', '', 'text_color' );
});
45 changes: 45 additions & 0 deletions src/js/admin/preset_customize_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import '../../scss/admin/preset_customize_control.scss';
'use strict';

jQuery( 'document' ).ready( function( $ ) {
function flatten( input ) {
const ret = {};
$.each( input, function( key, value ) {
if ( 'object' === typeof ( value ) ) {
$.each( value, function( subKey, subValue ) {
ret[key + '[' + subKey + ']'] = subValue;
});
} else {
ret[key] = value;
}
});
return ret;
}

wp.customize.control(
'crdm_basic_preset',
function( control ) {
const presets = [];
$.each( crdmbasicPresetCustomizeControlLocalize, function( key, value ) {
presets[key] = flatten( value );
});
control.container.find( 'input[name=crdm_basic_preset]' ).change( function() {
control.container.find( '.button' ).prop( 'disabled', false );
});
control.container.find( '.button' ).on( 'click', function() {
const chosen = control.container.find( 'input[name=crdm_basic_preset]:checked' ).val();
if ( ! chosen ) {
console.log( 'FAIL' );
return;
}
$.each( presets[chosen], function( key, value ) {
const setting = wp.customize( key );
if ( ! setting ) {
return;
}
setting.set( value );
});
});
}
);
});
22 changes: 22 additions & 0 deletions src/js/admin/typography_live_preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

jQuery( 'document' ).ready( function( $ ) {
generatepress_typography_live_update( 'navigation_font_size', '.main-navigation a, .menu-toggle', 'font-size', 'px', crdmTypographyLivePreview.desktop );
generatepress_typography_live_update( 'mobile_navigation_font_size', '.main-navigation:not(.slideout-navigation) a, .menu-toggle', 'font-size', 'px', crdmTypographyLivePreview.mobile );
generatepress_typography_live_update( 'navigation_font_weight', '.main-navigation a, .menu-toggle', 'font-weight' );
generatepress_typography_live_update( 'navigation_font_transform', '.main-navigation a, .menu-toggle', 'text-transform' );

generatepress_typography_live_update( 'heading_1_font_size', 'h1', 'font-size', 'px', crdmTypographyLivePreview.desktop );
generatepress_typography_live_update( 'mobile_heading_1_font_size', 'h1', 'font-size', 'px', crdmTypographyLivePreview.mobile );
generatepress_typography_live_update( 'heading_1_weight', 'h1', 'font-weight' );
generatepress_typography_live_update( 'heading_1_transform', 'h1', 'text-transform' );
generatepress_typography_live_update( 'heading_1_line_height', 'h1', 'line-height', 'em' );
generatepress_typography_live_update( 'heading_1_margin_bottom', 'h1', 'margin-bottom', 'px' );

generatepress_typography_live_update( 'heading_2_font_size', 'h2', 'font-size', 'px', crdmTypographyLivePreview.desktop );
generatepress_typography_live_update( 'mobile_heading_2_font_size', 'h2', 'font-size', 'px', crdmTypographyLivePreview.mobile );
generatepress_typography_live_update( 'heading_2_weight', 'h2', 'font-weight' );
generatepress_typography_live_update( 'heading_2_transform', 'h2', 'text-transform' );
generatepress_typography_live_update( 'heading_2_line_height', 'h2', 'line-height', 'em' );
generatepress_typography_live_update( 'heading_2_margin_bottom', 'h2', 'margin-bottom', 'px' );
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Contains the Background_Image_Customize_Control class.
*
* @package crdm-basic
*/

declare(strict_types = 1);

namespace CrdmBasic\Customizer\Controls;

/**
* A WP_Customize_Control for background image configuration
*
* Allows for controlling the repeat, size, attachment and position of a background image.
*/
class Background_Image_Customize_Control extends \WP_Customize_Control {

/**
* Control's type.
*
* @var string
*/
public $type = 'crdm-basic-background-image';

/**
* Exports control parameters for JS.
*
* @inheritDoc
*/
public function to_json() {
parent::to_json();

$this->json['position_description'] = esc_html__( 'left top, x%, y%, xpos ypos (px)', 'crdm-basic' );
$this->json['position_placeholder'] = esc_html__( 'Position', 'crdm-basic' );

foreach ( $this->settings as $key => $id ) {
$this->json['settings'][ $key ] = array(
'link' => $this->get_link( $key ),
'value' => $this->value( $key ),
'id' => $id->id ?? '',
);
}

$this->json['repeat_choices'] = array(
'' => esc_html__( 'Repeat', 'crdm-basic' ),
'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ),
'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ),
'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ),
);
$this->json['size_choices'] = array(
'' => esc_html__( 'Size (Auto)', 'crdm-basic' ),
'100' => esc_html__( '100% Width', 'crdm-basic' ),
'cover' => esc_html__( 'Cover', 'crdm-basic' ),
'contain' => esc_html__( 'Contain', 'crdm-basic' ),
);
$this->json['attachment_choices'] = array(
'' => esc_html__( 'Attachment', 'crdm-basic' ),
'fixed' => esc_html__( 'Fixed', 'crdm-basic' ),
'local' => esc_html__( 'Local', 'crdm-basic' ),
'inherit' => esc_html__( 'Inherit', 'crdm-basic' ),
);
}

/**
* Prints the Underscore.js template for the control.
*
* @inheritDoc
*/
public function content_template() {
?>
<# _.each( [ [ data.settings.repeat, data.repeat_choices ], [ data.settings.size, data.size_choices ], [ data.settings.attachment, data.attachment_choices] ], function( tuple ) {
if ( tuple[0] ) { #>
<label>
<select {{{ tuple[0].link }}}>
<# _.each( tuple[1], function( label, choice ) { #>
<option value="{{{ choice }}}" <# if ( choice === tuple[0].value ) { #> selected="selected" <# } #>>{{{ label }}}</option>
<# } ) #>
</select>
</label>
<# }
} ); #>

<# if ( data.settings.position ) { #>
<label>
<input name="{{{ data.settings.position.id }}}" type="text" {{{ data.settings.position.link }}} value="{{{ data.settings.position.value }}}" placeholder="{{{ data.position_placeholder }}}" />
<p class="description">{{{ data.position_description }}}</p>
</label>
<# } #>
<?php
}
}
Loading