Skip to content

Commit 9ae9f87

Browse files
committed
Merge branch 'master' of github.com:Mill3/mill3-wp-theme-boilerplate
2 parents 3a3eca9 + d73e2e1 commit 9ae9f87

File tree

21 files changed

+163
-83
lines changed

21 files changed

+163
-83
lines changed

.postcssrc.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ if( !DEV ) {
6363
// add more here if needed
6464
],
6565
deep: [
66+
/^body/,
6667
/^wysiwyg/,
6768
/^btn/,
6869
/^gform/,

archive.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
$context['title'] = single_cat_title('', false);
3030
array_unshift($templates, 'archive-' . get_query_var('cat') . '.twig');
3131
} elseif (is_post_type_archive()) {
32+
$post_type = get_post_type();
33+
if( empty($post_type) ) $post_type = get_query_var('post_type');
34+
3235
$context['title'] = post_type_archive_title('', false);
33-
array_unshift($templates, 'archive-' . get_post_type() . '.twig');
36+
array_unshift($templates, 'archive-' . $post_type . '.twig');
3437
}
3538

3639
Timber::render($templates, $context);

functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ public function add_functions($functions)
257257
$functions['get_options'] = ['callable' => function () { return get_fields('options'); }];
258258
$functions['is_menu_item'] = ['callable' => function ($item) { return ($item instanceof Timber\MenuItem); }];
259259
$functions['get_table_of_contents'] = ['callable' => 'Mill3\Twig\get_table_of_contents'];
260+
$functions['get_term_by'] = ['callable' => [Timber::class, 'get_term_by']];
261+
$functions['get_post_by'] = ['callable' => [Timber::class, 'get_post_by']];
260262

261263
return $functions;
262264
}

lib/post-type.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function dummy() {
126126
'show_in_menu' => true,
127127
'show_in_nav_menus' => true,
128128
'show_in_admin_bar' => true,
129+
'show_in_rest' => true, // required for enabling block editor
129130
'menu_position' => $this->incrementMenuPosition(),
130131
'can_export' => true,
131132
'has_archive' => true,
@@ -167,8 +168,7 @@ public function page_section()
167168
'show_in_menu' => true,
168169
'show_in_nav_menus' => false,
169170
'show_in_admin_bar' => true,
170-
// need this for enabling gutenberg editor
171-
'show_in_rest' => true,
171+
'show_in_rest' => true, // required for enabling block editor
172172
'menu_position' => $this->incrementMenuPosition(),
173173
'can_export' => true,
174174
'has_archive' => false,

lib/taxonomies.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ public function dummy()
103103
$taxonomy_name,
104104
array('post'),
105105
array(
106+
'labels' => $labels,
107+
'public' => true,
108+
'publicly_queryable' => true,
106109
'hierarchical' => true,
107-
'query_var' => true,
108110
'show_ui' => true,
109111
'show_in_menu' => true,
110112
'show_in_nav_menus' => true,
113+
'show_in_rest' => true, // required for editing in block editor
111114
'show_in_quick_edit' => true,
112115
'show_admin_column' => true,
113-
'labels' => $labels,
114116
// Control the slugs used for this taxonomy
115117
'rewrite' => array(
116118
'slug' => $slug, // This controls the base slug that will display before each term

src/js/ACF-Preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ domready(() => {
2727

2828
const resize = () => {
2929
const max = Math.ceil(parent.innerHeight * 2 >> 0);
30-
const height = document.body.querySelector('.pb-row-wrapper').getBoundingClientRect().height;
30+
const height = document.body.querySelector('[class*="-row-wrapper"]').getBoundingClientRect().height;
3131

3232
window.frameElement.height = Math.max(25, Math.min(max, height));
3333
};

src/js/core/windmill.scroll.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import EMITTER from "@core/emitter";
22
import { SCROLLBAR_HIDDEN_CLASSNAME, SCROLL_TO_OPTIONS } from "@scroll/constants";
33
import Scroll from "@scroll/scroll";
44
import ScrollDirection from "@scroll/scroll-direction";
5-
//import ScrollIntersection from "@scroll/scroll-intersection";
65
import ScrollIO from "@scroll/scroll-io";
76
import ScrollMinimum from "@scroll/scroll-minimum";
87
import ScrollParallax from "@scroll/scroll-parallax";
@@ -63,6 +62,7 @@ export class WindmillScroll {
6362
windmill.on('exit', this._onPageExit, this);
6463

6564
if( this._async ) {
65+
windmill.on('added', this._onAsyncPageAdded, this);
6666
windmill.on('entering', this._resetScrollModules, this);
6767
windmill.on('enter', this._onAsyncPageEnter, this);
6868
windmill.on('entered', this._onAsyncPageEntered, this);
@@ -78,7 +78,6 @@ export class WindmillScroll {
7878
_onInit() {
7979
this.scroll = new Scroll();
8080
this.direction = new ScrollDirection(this.scroll);
81-
//this.intersection = new ScrollIntersection(this.scroll);
8281
this.io = new ScrollIO(this.scroll);
8382
this.minimum = new ScrollMinimum(this.scroll);
8483
if( !mobile ) this.parallax = new ScrollParallax(this.scroll);
@@ -93,7 +92,6 @@ export class WindmillScroll {
9392
}
9493

9594
this.scroll.raf(delta);
96-
//this.intersection?.raf(delta);
9795
this.parallax?.raf(delta);
9896
//this.timeline?.raf();
9997
//this.webgl?.raf(delta);
@@ -103,7 +101,6 @@ export class WindmillScroll {
103101

104102
this.scroll?.resize();
105103
this.io?.resize();
106-
//this.intersection?.resize();
107104
this.parallax?.resize();
108105
//this.webgl?.resize();
109106
}
@@ -112,7 +109,6 @@ export class WindmillScroll {
112109
this.scroll?.init();
113110
//this.webgl?.init();
114111
this.io?.init();
115-
//this.intersection?.init();
116112
this.parallax?.init();
117113

118114
this._startModules();
@@ -124,27 +120,27 @@ export class WindmillScroll {
124120
}
125121
_onPageExit() {
126122
this.io?.exit();
127-
//this.intersection?.exit();
128123
}
129124
_onPageDone() {
130125
this.scroll?.resize();
131126
//this.webgl?.resize();
132127
this.io?.resize();
133-
//this.intersection?.resize();
134128
this.parallax?.resize();
135129
}
136130

137-
_onAsyncPageEnter({ next }) {
131+
_onAsyncPageAdded() {
138132
this._unbindEvents();
139133
this._stopModules();
140-
134+
this._resetScrollModules();
135+
}
136+
_onAsyncPageEnter({ next }) {
141137
html.classList.remove(SCROLLBAR_HIDDEN_CLASSNAME);
142138

143139
this.scroll?.init();
144140
//this.webgl?.init(next.container);
145141
this.io?.init(next.container);
146-
//this.intersection?.init(next.container);
147142
this.parallax?.init(next.container);
143+
this.io?.start();
148144
}
149145
_onAsyncPageEntered() {
150146
this._startModules();
@@ -155,7 +151,6 @@ export class WindmillScroll {
155151
_onSyncPageEnter({ next }) {
156152
this.scroll?.init();
157153
this.io?.init(next.container);
158-
//this.intersection?.init(next.container);
159154
this.parallax?.init(next.container);
160155
//this.webgl?.init();
161156

@@ -185,7 +180,6 @@ export class WindmillScroll {
185180
this.scroll?.resize();
186181
//this.webgl?.update();
187182
this.io?.update();
188-
//this.intersection?.update();
189183
this.parallax?.update();
190184

191185
// trigger event that scroll update is completed
@@ -221,7 +215,6 @@ export class WindmillScroll {
221215

222216
this.direction?.start();
223217
this.io?.start();
224-
//this.intersection?.start();
225218
this.parallax?.start();
226219
this.minimum?.start();
227220
//this.timeline?.start();
@@ -235,7 +228,6 @@ export class WindmillScroll {
235228
this.scroll?.stop();
236229
this.direction?.stop();
237230
this.io?.stop();
238-
//this.intersection?.stop();
239231
this.parallax?.stop();
240232
this.minimum?.stop();
241233
//this.timeline?.stop();
@@ -247,7 +239,6 @@ export class WindmillScroll {
247239
_resetScrollModules() {
248240
this.scroll?.reset();
249241
this.io?.reset();
250-
//this.intersection?.reset();
251242
this.parallax?.reset();
252243
this.minimum?.reset();
253244
//this.timeline?.reset();

src/js/modules/filtered-posts-list/index.js

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@
33
*
44
* How to use in your template :
55
*
6-
* 1. attach JS module to the container containing : SELECT element, all posts, pagination
6+
* 1. attach JS module to the container containing : SELECT element, filter links, all posts, pagination
77
*
8-
* <section data-module="filtered-posts-list" data-filtered-posts-list></section>
8+
* <section data-module="filtered-posts-list"></section>
99
*
10-
* 2. attach data-selector to SELECT element
10+
* 2. attach data-selector to SELECT element AND filter links
1111
*
12-
* <select class="my-ctp-archive__filter" data-filtered-posts-list-filters >
12+
* <select class="my-ctp-archive__filter" data-filtered-posts-list-filters>
1313
* <option value="{{ my-ctp_archive_link }}">{{ __('Filter by', 'mill3wp') }}</option>
1414
* <option value="{{ term.link }}">{{ term.name }}</option>
15+
*
16+
* <nav class="my-cpt-archive__links" data-filtered-posts-list-links>
17+
* <a href="#">All</a>
18+
* <a href="#">Filter 1</a>
19+
* <a href="#">Filter 2</a>
20+
* </nav>
1521
*
1622
* 3. attach data-selector to posts container
1723
*
18-
* <ol data-filtered-posts-list-results >
24+
* <ol data-filtered-posts-list-results>
1925
* {% for post in posts %}
2026
* ...
2127
* </ol>
2228
*
2329
* 4. attach data-selector to pagination element
2430
*
2531
* <div data-filtered-posts-list-pagination>
26-
* {% include 'partial/pagination.twig' }
32+
* {% include 'partial/pagination.twig' %}
2733
* </div>
2834
*
2935
*/
@@ -36,6 +42,7 @@ import { on, off } from "@utils/listener";
3642

3743
const LOCKED_CLASSNAME = "--js-filtered-posts-list-locked";
3844
const FILTERS_SELECTOR = "[data-filtered-posts-list-filters]";
45+
const LINKS_SELECTOR = "[data-filtered-posts-list-links]";
3946
const PAGINATION_SELECTOR = "[data-filtered-posts-list-pagination]";
4047
const RESULTS_SELECTOR = "[data-filtered-posts-list-results]";
4148

@@ -45,6 +52,7 @@ class FilteredPostsList {
4552
this.emitter = emitter;
4653

4754
this.filters = $(FILTERS_SELECTOR, this.el);
55+
this.links = $(LINKS_SELECTOR, this.el);
4856
this.pagination = $(PAGINATION_SELECTOR, this.el);
4957
this.results = $(RESULTS_SELECTOR, this.el);
5058

@@ -54,6 +62,7 @@ class FilteredPostsList {
5462
this._newResultsHTML = null;
5563

5664
this._onTypeChange = this._onTypeChange.bind(this);
65+
this._onLinkClick = this._onLinkClick.bind(this);
5766
this._onAjaxCallback = this._onAjaxCallback.bind(this);
5867
this._onAjaxResponse = this._onAjaxResponse.bind(this);
5968
this._onAjaxError = this._onAjaxError.bind(this);
@@ -70,6 +79,7 @@ class FilteredPostsList {
7079
this.el = null;
7180
this.emitter = null;
7281
this.filters = null;
82+
this.links = null;
7383
this.pagination = null;
7484
this.results = null;
7585

@@ -79,6 +89,7 @@ class FilteredPostsList {
7989
this._newResultsHTML = null;
8090

8191
this._onTypeChange = null;
92+
this._onLinkClick = null;
8293
this._onAjaxCallback = null;
8394
this._onAjaxResponse = null;
8495
this._onAjaxError = null;
@@ -88,9 +99,11 @@ class FilteredPostsList {
8899

89100
_bindEvents() {
90101
if(this.filters) on(this.filters, 'change', this._onTypeChange);
102+
if(this.links) on(this.links, 'click', this._onLinkClick);
91103
}
92104
_unbindEvents() {
93105
if(this.filters) off(this.filters, 'change', this._onTypeChange);
106+
if(this.links) off(this.links, 'click', this._onLinkClick);
94107
}
95108

96109
_onTypeChange() {
@@ -108,6 +121,39 @@ class FilteredPostsList {
108121
.then(this._onAjaxResponse)
109122
.catch(this._onAjaxError);
110123
}
124+
_onLinkClick(event) {
125+
if( event ) {
126+
event.preventDefault();
127+
event.stopImmediatePropagation();
128+
}
129+
130+
131+
let href, target = event.target;
132+
133+
// check all parent elements until we reach [data-filtered-posts-list-links]
134+
while( target && target !== this.links ) {
135+
if( target.tagName.toString().toUpperCase() === 'A' ) {
136+
href = target.href;
137+
break;
138+
}
139+
140+
target = target.parentElement;
141+
}
142+
143+
if( !href ) return;
144+
145+
// replace current history state
146+
windmill.replace(href);
147+
148+
// block UI
149+
if( this.el ) this.el.classList.add(LOCKED_CLASSNAME);
150+
151+
// fetch HTML
152+
fetch(href)
153+
.then(this._onAjaxCallback)
154+
.then(this._onAjaxResponse)
155+
.catch(this._onAjaxError);
156+
}
111157
_onAjaxCallback(response) {
112158
// stop here if module has been destroyed during Fetch request
113159
if( !this.el ) return;
@@ -125,6 +171,8 @@ class FilteredPostsList {
125171

126172
const doc = this._parser.parseFromString(html, "text/html");
127173
const title = $('html title', doc);
174+
const filters = $(FILTERS_SELECTOR, doc);
175+
const links = $(LINKS_SELECTOR, doc);
128176
const results = $(RESULTS_SELECTOR, doc);
129177
const pagination = $(PAGINATION_SELECTOR, doc);
130178

@@ -134,6 +182,10 @@ class FilteredPostsList {
134182
return;
135183
}
136184

185+
// update filters and links immediately
186+
if( filters && this.filters ) this.filters.innerHTML = filters.innerHTML;
187+
if( links && this.links ) this.links.innerHTML = links.innerHTML;
188+
137189
// save new content
138190
this._newPageTitle = title.innerText;
139191
this._newResultsHTML = results.innerHTML;

src/js/modules/pb-row-oembed/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class PbRowOEmbed {
77
this.emitter = emitter;
88
this.wrapper = $('.pb-row-oembed__wrapper', this.el);
99
this.preview = $('.pb-row-oembed__preview', this.el);
10+
this.videoPreview = $('.pb-row-oembed__videoPreview', this.el);
1011
this.script = $('script', this.el);
1112

1213
this._onClick = this._onClick.bind(this);
@@ -42,8 +43,13 @@ class PbRowOEmbed {
4243

4344
this._unbindEvents();
4445

46+
if( this.videoPreview ) this.emitter.emit('Video.destroy', this.videoPreview);
47+
4548
this.preview = null;
49+
this.videoPreview = null;
4650
this.wrapper.innerHTML = this.script.innerHTML;
51+
52+
this.emitter.emit('SiteScroll.update');
4753
this.emitter.emit('oEmbed.add', $('iframe', this.wrapper));
4854
}
4955
}

src/js/scroll/scroll.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import EMITTER from "@core/emitter";
44
import { DIRECTION_DOWN, DIRECTION_UP, SCROLL_TO_OPTIONS } from "@scroll/constants";
55
import { firefox } from "@utils/browser";
66
import { $, $$, html, body, rect } from "@utils/dom";
7+
import { isCSSSelectorValid } from "@utils/is";
78
import { on, off } from "@utils/listener";
89
import { lerp2, limit } from "@utils/math";
910
import { mobile, motion_reduced } from "@utils/mobile";
@@ -64,10 +65,13 @@ class Scroll {
6465
if( window.location.hash ) {
6566
// Get the hash without the '#' and find the matching element
6667
const id = window.location.hash.slice(1, window.location.hash.length);
67-
let target = $(`#${id}`);
6868

69-
// If found, scroll to the element
70-
if (target) this.scrollTo(target);
69+
if( isCSSSelectorValid(id) ) {
70+
let target = $(`#${id}`);
71+
72+
// If found, scroll to the element
73+
if (target) this.scrollTo(target);
74+
}
7175
}
7276
}
7377
raf(delta = 1) {

0 commit comments

Comments
 (0)