Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from cagov/1.0.11.2
Browse files Browse the repository at this point in the history
1.0.11.2
  • Loading branch information
chachasikes authored Jun 30, 2021
2 parents 0f846cf + ac4a2ac commit 097d26b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 45 deletions.
64 changes: 29 additions & 35 deletions blocks/content-navigation/web-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ class CAGovContentNavigation extends window.HTMLElement {
connectedCallback() {
this.type = "wordpress";

/* https://unpkg.com/[email protected]/dist/smoothscroll.min.js */
/* Smooth scroll polyfill for safari, since it does not support scroll behaviors yet - can be moved to a dependency bundle split out by browser support later or in headless implementation */
// !function(){"use strict";function o(){var o=window,t=document;if(!("scrollBehavior"in t.documentElement.style&&!0!==o.__forceSmoothScrollPolyfill__)){var l,e=o.HTMLElement||o.Element,r=468,i={scroll:o.scroll||o.scrollTo,scrollBy:o.scrollBy,elementScroll:e.prototype.scroll||n,scrollIntoView:e.prototype.scrollIntoView},s=o.performance&&o.performance.now?o.performance.now.bind(o.performance):Date.now,c=(l=o.navigator.userAgent,new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(l)?1:0);o.scroll=o.scrollTo=function(){void 0!==arguments[0]&&(!0!==f(arguments[0])?h.call(o,t.body,void 0!==arguments[0].left?~~arguments[0].left:o.scrollX||o.pageXOffset,void 0!==arguments[0].top?~~arguments[0].top:o.scrollY||o.pageYOffset):i.scroll.call(o,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:o.scrollX||o.pageXOffset,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:o.scrollY||o.pageYOffset))},o.scrollBy=function(){void 0!==arguments[0]&&(f(arguments[0])?i.scrollBy.call(o,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:0,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:0):h.call(o,t.body,~~arguments[0].left+(o.scrollX||o.pageXOffset),~~arguments[0].top+(o.scrollY||o.pageYOffset)))},e.prototype.scroll=e.prototype.scrollTo=function(){if(void 0!==arguments[0])if(!0!==f(arguments[0])){var o=arguments[0].left,t=arguments[0].top;h.call(this,this,void 0===o?this.scrollLeft:~~o,void 0===t?this.scrollTop:~~t)}else{if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");i.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left:"object"!=typeof arguments[0]?~~arguments[0]:this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top:void 0!==arguments[1]?~~arguments[1]:this.scrollTop)}},e.prototype.scrollBy=function(){void 0!==arguments[0]&&(!0!==f(arguments[0])?this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior}):i.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop))},e.prototype.scrollIntoView=function(){if(!0!==f(arguments[0])){var l=function(o){for(;o!==t.body&&!1===(e=p(l=o,"Y")&&a(l,"Y"),r=p(l,"X")&&a(l,"X"),e||r);)o=o.parentNode||o.host;var l,e,r;return o}(this),e=l.getBoundingClientRect(),r=this.getBoundingClientRect();l!==t.body?(h.call(this,l,l.scrollLeft+r.left-e.left,l.scrollTop+r.top-e.top),"fixed"!==o.getComputedStyle(l).position&&o.scrollBy({left:e.left,top:e.top,behavior:"smooth"})):o.scrollBy({left:r.left,top:r.top,behavior:"smooth"})}else i.scrollIntoView.call(this,void 0===arguments[0]||arguments[0])}}function n(o,t){this.scrollLeft=o,this.scrollTop=t}function f(o){if(null===o||"object"!=typeof o||void 0===o.behavior||"auto"===o.behavior||"instant"===o.behavior)return!0;if("object"==typeof o&&"smooth"===o.behavior)return!1;throw new TypeError("behavior member of ScrollOptions "+o.behavior+" is not a valid value for enumeration ScrollBehavior.")}function p(o,t){return"Y"===t?o.clientHeight+c<o.scrollHeight:"X"===t?o.clientWidth+c<o.scrollWidth:void 0}function a(t,l){var e=o.getComputedStyle(t,null)["overflow"+l];return"auto"===e||"scroll"===e}function d(t){var l,e,i,c,n=(s()-t.startTime)/r;c=n=n>1?1:n,l=.5*(1-Math.cos(Math.PI*c)),e=t.startX+(t.x-t.startX)*l,i=t.startY+(t.y-t.startY)*l,t.method.call(t.scrollable,e,i),e===t.x&&i===t.y||o.requestAnimationFrame(d.bind(o,t))}function h(l,e,r){var c,f,p,a,h=s();l===t.body?(c=o,f=o.scrollX||o.pageXOffset,p=o.scrollY||o.pageYOffset,a=i.scroll):(c=l,f=l.scrollLeft,p=l.scrollTop,a=n),d({scrollable:c,method:a,startTime:h,startX:f,startY:p,x:e,y:r})}}"object"==typeof exports&&"undefined"!=typeof module?module.exports={polyfill:o}:o()}();

if (this.type === "wordpress") {
document.addEventListener("DOMContentLoaded", () =>
this.buildContentNavigation()
);

// Still in progress, will update content dynamically on content editing
// document.addEventListener("GutenbergEditorUpdated", (e) =>
// this.buildContentNavigation(e)
// );
}
}

Expand Down Expand Up @@ -44,16 +43,27 @@ class CAGovContentNavigation extends window.HTMLElement {
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
let hashval = anchor.getAttribute("href");
let target = document.querySelector(hashval);
let position = target.getBoundingClientRect();
window.scrollTo({
behavior: "smooth",
left: position.left,
top: position.top - 200
});

history.pushState(null, null, hashval);

try {
let target = document.querySelector(hashval);
if (target !== null) {
let position = target.getBoundingClientRect();

const prefersReducedMotion = window.matchMedia(
"(prefers-reduced-motion)"
).matches;
if (!prefersReducedMotion) {
window.scrollTo({
behavior: "smooth",
left: position.left,
top: position.top - 200,
});
}

history.pushState(null, null, hashval);
}
} catch (error) {
console.error(error);
}
e.preventDefault();
});
});
Expand All @@ -75,16 +85,10 @@ class CAGovContentNavigation extends window.HTMLElement {

var h = ["h2"];
var headings = [];

// console.log("reading headers");
for (var i = 0; i < h.length; i++) {
// Pull out the header tags, in order & render as links with anchor tags
// auto convert h tags with tag names
if (selector !== undefined && selector !== null) {
// Dynamic for editor
// @TODO update on save like category-label
// data-selector="article" data-editor="textarea.block-editor-plain-text" data-callback="(content) => unescape(content)" data-js-flip="true"

if (display === "render") {
let selectorContent = document.querySelector(selector);
if (selectorContent !== null) {
Expand All @@ -93,18 +97,6 @@ class CAGovContentNavigation extends window.HTMLElement {
}
}
}

// if (editor !== undefined && editor !== null && document.querySelector(editor) !== null) {
// let editorContent = window.document.querySelector(`${editor}`);

// let editorInnerHTML = selectorContent.innerHTML;
// if (callback !== undefined && callback !== null) {
// editorInnerHTML = callback(editorInnerHTML);
// }

// let outline = this.outliner(editorContent);
// return outline;
// }
}
return null;
}
Expand All @@ -117,14 +109,16 @@ class CAGovContentNavigation extends window.HTMLElement {
let tagId = tag.getAttribute("id");
let title = tag.innerHTML;

let anchor = tag.innerHTML.toLowerCase().trim().replace(/ /g, "-");
let anchor = tag.innerHTML.toLowerCase().trim().replace(/ /g, "-").replace(/\(|\)|\!|\"|\#|\$|\%|\&|\'|\*|\+|\,|\.|\/|\:|\;|\<|\=|\>|\?|\@|\[|\]|\\|\^|\`|\{|\||\|\}|\~/g, "");
// These are the CSS unallowed characters.
// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, `, {, |, }, and ~.

// If id not set already, create an id to jump to.
if (tagId !== undefined && tagId !== null) {
anchor = tagId;
}

output += `<li><a href="#${anchor}">${title}</a></li>`;
output += `<li><a href="#${encodeURI(anchor)}">${title}</a></li>`;

if (tagId === undefined || tagId === null) {
tagId = anchor;
Expand Down
4 changes: 2 additions & 2 deletions ca-design-system-gutenberg-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: Gutenberg blocks for CA Design System
* Author: Office of Digital Innovation
* Author URI: https://digital.ca.gov
* Version: 1.0.11
* Version: 1.0.12
* License: MIT
* License URI: https://opensource.org/licenses/MIT
* Text Domain: ca-design-system
Expand All @@ -22,7 +22,7 @@
}

// Constants.
define('CA_DESIGN_SYSTEM_GUTENBERG_BLOCKS__VERSION', '1.0.11');
define('CA_DESIGN_SYSTEM_GUTENBERG_BLOCKS__VERSION', '1.0.12');
define('CA_DESIGN_SYSTEM_GUTENBERG_BLOCKS__BLOCKS_DIR_PATH', plugin_dir_path(__FILE__));
define('CA_DESIGN_SYSTEM_GUTENBERG_BLOCKS__ADMIN_URL', plugin_dir_url(__FILE__));
define('CA_DESIGN_SYSTEM_GUTENBERG_BLOCKS__FILE', __FILE__);
Expand Down
16 changes: 8 additions & 8 deletions includes/page-resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@
add_action( 'caweb_pre_main_area', 'cagov_breadcrumb');
add_action( 'caweb_pre_main_primary', 'cagov_pre_main_primary' );
add_action( 'caweb_pre_footer', 'cagov_content_menu' );

add_action( 'wp_head', 'cagov_footer_scripts');
add_action('cagov_breadcrumb', 'cagov_breadcrumb');
add_action('cagov_content_menu', 'cagov_content_menu');

// @TODO add api to make this content available





/**
* CADesignSystem Breadcrumb
*
Expand Down Expand Up @@ -85,6 +79,12 @@ function cagov_breadcrumb()

echo '<div class="breadcrumb" aria-label="Breadcrumb" role="region">' . implode($separator, $crumbs) . '</div>';
}
function cagov_footer_scripts() {
/* Register cagov scripts */
wp_register_script( 'twitter-timeline', 'https://platform.twitter.com/widgets.js', array(), CAWEB_VERSION, false );

wp_enqueue_script( 'twitter-timeline' );
}

/**
* CADesignSystem Pre Main Primary
Expand Down Expand Up @@ -225,7 +225,7 @@ function cagov_content_social_menu()
$social_icon = !empty($share) ? '' : '';
?>
<li>
<a href="<?php echo esc_url($social_url); ?>" title="<?php echo esc_attr($title); ?>" target="<?php echo esc_attr($social_target); ?>">
<a href="<?php echo esc_url($social_url); ?>" title="<?php echo esc_attr($title); ?>" target="<?php echo esc_attr($social_target); ?>" rel="noopener">
<?php if (!empty($share)) : ?>
<span class="ca-gov-icon-<?php echo esc_attr($share); ?>"></span>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions styles/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
}

#main-content.landing {
margin-top: 32px;
margin-bottom: 32px;
}

Expand Down

0 comments on commit 097d26b

Please sign in to comment.