Skip to content

Commit dc62c03

Browse files
authored
Merge pull request #397 from devgeniem/TMS-768
TMS-768: Duet Date Picker from CDN
2 parents 9cbcebd + d48e73c commit dc62c03

6 files changed

Lines changed: 350 additions & 514 deletions

File tree

CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Fixed
1111

12+
- TMS-768: Duet Date Picker from CDN to prevent build issues that sometimes break JS
13+
14+
### Changed
15+
1216
- Fix image clickable option #396
1317
- TMS-674: Fix modaal background focus & translations #395
1418
- TMS-769: Fix issue with countdown block text contrast in certain color schemes. #394

assets/scripts/date-picker.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Date Picker controller.
44
*/
55

6-
import { defineCustomElements } from '@duetds/date-picker/dist/loader';
7-
86
/**
97
* Export the class reference.
108
*/
@@ -66,5 +64,3 @@ export default class DatePicker {
6664
} );
6765
}
6866
}
69-
70-
defineCustomElements( window );

assets/styles/main.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ $tablet: 680px;
5050
# External resources
5151
--------------------------------------------------------------*/
5252
@import "~modaal/source/css/modaal";
53-
@import "~@duetds/date-picker/dist/duet/themes/default.css";

lib/Assets.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public function hooks() : void {
6363
10,
6464
0
6565
);
66+
67+
add_filter(
68+
'script_loader_tag',
69+
\Closure::fromCallable( [ $this, 'add_script_attributes' ] ),
70+
10,
71+
2
72+
);
6673
}
6774

6875
/**
@@ -158,6 +165,43 @@ private function enqueue_assets() : void {
158165
] );
159166

160167
\wp_dequeue_style( 'wp-block-library' );
168+
169+
\wp_enqueue_script( // phpcs:ignore
170+
'duet-date-picker-module',
171+
'https://cdn.jsdelivr.net/npm/@duetds/date-picker@1.4.0/dist/duet/duet.esm.js',
172+
[ 'jquery' ],
173+
null,
174+
false
175+
);
176+
177+
\wp_enqueue_script( // phpcs:ignore
178+
'duet-date-picker-nomodule',
179+
'https://cdn.jsdelivr.net/npm/@duetds/date-picker@1.4.0/dist/duet/duet.js',
180+
[ 'jquery' ],
181+
null,
182+
false
183+
);
184+
}
185+
186+
/**
187+
* Add attributes to enqueued script tags
188+
*
189+
* @param string $tag Script tag.
190+
* @param string $handle Script handle name.
191+
* @return string The script tag.
192+
*/
193+
private function add_script_attributes( $tag, $handle ) : string {
194+
195+
if ( $handle === 'duet-date-picker-module' ) {
196+
$tag = str_replace( '<script ', ' <script type="module" ', $tag );
197+
return $tag;
198+
}
199+
200+
if ( $handle === 'duet-date-picker-nomodule' ) {
201+
$tag = str_replace( '<script ', ' <script nomodule ', $tag );
202+
return $tag;
203+
}
204+
return $tag;
161205
}
162206

163207
/**

0 commit comments

Comments
 (0)