Browse Source

Change toggle UX, minor cleanup

pull/186/head
Dac Chartrand 7 years ago
parent
commit
1b85d1fdd3
  1. 32
      assets/scripts/customizer-toggle.js
  2. 4
      dist/mix-manifest.json
  3. 2
      dist/scripts/customizer-toggle.js
  4. 3
      functions.php
  5. 97
      inc/customizer/namespace.php
  6. 45
      package-lock.json

32
assets/scripts/customizer-toggle.js

@ -1,25 +1,33 @@
document.addEventListener( 'DOMContentLoaded', function () {
let checkbox = document.getElementById( '_customize-input-pb_network_contact_form' );
let email = document.querySelector( '#_customize-input-pb_network_contact_email' );
let link = document.querySelector( '#_customize-input-pb_network_contact_link' );
let title = document.querySelector( '#_customize-input-pb_network_contact_form_title' );
let email = document.getElementById( 'customize-control-pb_network_contact_email' );
let link = document.getElementById( 'customize-control-pb_network_contact_link' );
let title = document.getElementById( 'customize-control-pb_network_contact_form_title' );
checkbox.addEventListener( 'click', toggleReadOnly );
function toggleReadOnly(){
if ( checkbox.checked === false ){
email.setAttribute( 'readonly', 'readonly' );
title.setAttribute( 'readonly', 'readonly' );
function toggleReadOnly() {
if ( checkbox.checked === false ) {
email.classList.add( 'hidden' );
email.style.cssText = null;
link.removeAttribute( 'readonly' );
title.classList.add( 'hidden' );
title.style.cssText = null;
link.classList.remove( 'hidden' );
link.style.cssText = 'display: list-item;';
} else {
email.removeAttribute( 'readonly' );
title.removeAttribute( 'readonly' );
email.classList.remove( 'hidden' );
email.style.cssText = 'display: list-item;';
title.classList.remove( 'hidden' );
title.style.cssText = 'display: list-item;';
link.setAttribute( 'readonly', 'readonly' );
link.classList.add( 'hidden' );
link.style.cssText = null;
}
}
toggleReadOnly();
} )
} );

4
dist/mix-manifest.json vendored

@ -5,6 +5,6 @@
"/scripts/call-to-action.js": "/scripts/call-to-action.js?id=14b2ac09b5fc52660522",
"/scripts/catalog-admin.js": "/scripts/catalog-admin.js?id=43511dff74631c962103",
"/scripts/customizer.js": "/scripts/customizer.js?id=cd5dc6157cc6b89dc521",
"/scripts/customizer-toggle.js": "/scripts/customizer-toggle.js?id=1c22f3d5b5cb63f75533",
"/scripts/customizer-toggle.js": "/scripts/customizer-toggle.js?id=38614b765cca526519d0",
"/scripts/page-section.js": "/scripts/page-section.js?id=b62a3319a10d83a36aea"
}
}

2
dist/scripts/customizer-toggle.js vendored

@ -1 +1 @@
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=4)}({4:function(e,t,n){e.exports=n("5MvR")},"5MvR":function(e,t){document.addEventListener("DOMContentLoaded",function(){var e=document.getElementById("_customize-input-pb_network_contact_form"),t=document.querySelector("#_customize-input-pb_network_contact_email"),n=document.querySelector("#_customize-input-pb_network_contact_link"),r=document.querySelector("#_customize-input-pb_network_contact_form_title");function o(){!1===e.checked?(t.setAttribute("readonly","readonly"),r.setAttribute("readonly","readonly"),n.removeAttribute("readonly")):(t.removeAttribute("readonly"),r.removeAttribute("readonly"),n.setAttribute("readonly","readonly"))}e.addEventListener("click",o),o()})}});
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=4)}({4:function(e,t,n){e.exports=n("5MvR")},"5MvR":function(e,t){document.addEventListener("DOMContentLoaded",function(){var e=document.getElementById("_customize-input-pb_network_contact_form"),t=document.getElementById("customize-control-pb_network_contact_email"),n=document.getElementById("customize-control-pb_network_contact_link"),o=document.getElementById("customize-control-pb_network_contact_form_title");function r(){!1===e.checked?(t.classList.add("hidden"),t.style.cssText=null,o.classList.add("hidden"),o.style.cssText=null,n.classList.remove("hidden"),n.style.cssText="display: list-item;"):(t.classList.remove("hidden"),t.style.cssText="display: list-item;",o.classList.remove("hidden"),o.style.cssText="display: list-item;",n.classList.add("hidden"),n.style.cssText=null)}e.addEventListener("click",r),r()})}});

3
functions.php

@ -65,7 +65,8 @@ add_action( 'updated_option', '\Aldine\Actions\add_color_variants', 10, 3 );
add_action( 'customize_register', '\Aldine\Customizer\customize_register' );
add_action( 'customize_preview_init', '\Aldine\Customizer\customize_preview_js' );
add_action( 'customize_controls_enqueue_scripts', '\Aldine\Customizer\enqueue_color_contrast_validator' );
add_action( 'customize_controls_enqueue_scripts', '\Aldine\Customizer\enqueue_customizer_scripts' );
add_action( 'customize_controls_enqueue_scripts', '\Aldine\Customizer\enqueue_contact_form_tweaks' );
add_action( 'customize_controls_enqueue_scripts', '\Aldine\Customizer\enqueue_pb_a11y_in_customizer' );
// Shortcodes
add_shortcode( 'aldine_page_section', '\Aldine\Shortcodes\page_section' );

97
inc/customizer/namespace.php

@ -26,8 +26,6 @@ function customize_register( \WP_Customize_Manager $wp_customize ) {
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
if ( isset( $wp_customize->selective_refresh ) ) {
$wp_customize->selective_refresh->add_partial(
'blogname', [
@ -198,7 +196,6 @@ function customize_register( \WP_Customize_Manager $wp_customize ) {
$wp_customize->add_setting(
'pb_network_contact_form', [
'type' => 'option',
'transport' => 'refresh',
]
);
$wp_customize->add_control(
@ -209,46 +206,46 @@ function customize_register( \WP_Customize_Manager $wp_customize ) {
'type' => 'checkbox',
]
);
$wp_customize->add_setting(
'pb_network_contact_form_title', [
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field',
'default' => __( 'Contact Us', 'pressbooks-aldine' ),
]
);
$wp_customize->add_control(
'pb_network_contact_form_title', [
'label' => __( 'Contact Form Title', 'pressbooks-aldine' ),
'section' => 'pb_network_contact_form',
'settings' => 'pb_network_contact_form_title',
]
);
$wp_customize->add_setting(
'pb_network_contact_email', [
'type' => 'option',
'default' => get_option( 'admin_email', '' ),
'sanitize_callback' => 'sanitize_email',
]
);
$wp_customize->add_control(
'pb_network_contact_email', [
'label' => __( 'Contact Email', 'pressbooks-aldine' ),
'section' => 'pb_network_contact_form',
'settings' => 'pb_network_contact_email',
]
);
$wp_customize->add_setting(
'pb_network_contact_link', [
'type' => 'option',
]
);
$wp_customize->add_control(
'pb_network_contact_link', [
'label' => __( 'Contact Link', 'pressbooks-aldine' ),
'section' => 'pb_network_contact_form',
'settings' => 'pb_network_contact_link',
]
);
$wp_customize->add_setting(
'pb_network_contact_form_title', [
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field',
'default' => __( 'Contact Us', 'pressbooks-aldine' ),
]
);
$wp_customize->add_control(
'pb_network_contact_form_title', [
'label' => __( 'Contact Form Title', 'pressbooks-aldine' ),
'section' => 'pb_network_contact_form',
'settings' => 'pb_network_contact_form_title',
]
);
$wp_customize->add_setting(
'pb_network_contact_email', [
'type' => 'option',
'default' => get_option( 'admin_email', '' ),
'sanitize_callback' => 'sanitize_email',
]
);
$wp_customize->add_control(
'pb_network_contact_email', [
'label' => __( 'Contact Email', 'pressbooks-aldine' ),
'section' => 'pb_network_contact_form',
'settings' => 'pb_network_contact_email',
]
);
$wp_customize->add_setting(
'pb_network_contact_link', [
'type' => 'option',
]
);
$wp_customize->add_control(
'pb_network_contact_link', [
'label' => __( 'Contact Link', 'pressbooks-aldine' ),
'section' => 'pb_network_contact_form',
'settings' => 'pb_network_contact_link',
]
);
}
/**
@ -291,11 +288,19 @@ function enqueue_color_contrast_validator() {
);
}
function enqueue_customizer_scripts() {
/**
* Contact form UI tweaks (checkbox should toggle either/or)
*/
function enqueue_contact_form_tweaks() {
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
$pb_a11y_script = plugin_dir_url( 'pressbooks' ) . 'pressbooks/assets/src/scripts/a11y.js';
wp_enqueue_script( 'aldine/customizer-toggle', $assets->getPath( 'scripts/customizer-toggle.js' ) );
}
/**
* Enqueue pb-a11y hacks in customizer
*/
function enqueue_pb_a11y_in_customizer() {
$pb_a11y_script = plugin_dir_url( 'pressbooks' ) . 'pressbooks/assets/src/scripts/a11y.js';
wp_enqueue_script( 'pb-a11y', $pb_a11y_script, [ 'wp-i18n' ], false, true );
wp_enqueue_script( 'aldine/customizer-toggle', $assets->getPath( 'scripts/customizer-toggle.js' ), [ 'wp-i18n', 'pb-a11y' ], null );
}

45
package-lock.json generated

@ -2767,7 +2767,7 @@
},
"buffer": {
"version": "4.9.1",
"resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
"dev": true,
"requires": {
@ -6806,7 +6806,8 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
"bundled": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
@ -6824,11 +6825,13 @@
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -6841,15 +6844,18 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -6952,7 +6958,8 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true
"bundled": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@ -6962,6 +6969,7 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -6974,17 +6982,20 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true
"bundled": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -7001,6 +7012,7 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -7073,7 +7085,8 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -7083,6 +7096,7 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -7158,7 +7172,8 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true
"bundled": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
@ -7188,6 +7203,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -7205,6 +7221,7 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -7243,11 +7260,13 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true
"bundled": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true
"bundled": true,
"optional": true
}
}
},
@ -14054,7 +14073,7 @@
},
"rgba-regex": {
"version": "1.0.0",
"resolved": "http://registry.npmjs.org/rgba-regex/-/rgba-regex-1.0.0.tgz",
"resolved": "https://registry.npmjs.org/rgba-regex/-/rgba-regex-1.0.0.tgz",
"integrity": "sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=",
"dev": true
},

Loading…
Cancel
Save