Skip to content

Commit f0b77ac

Browse files
committed
refactor: port over pattern-finder; add deps, fix JS errors + add basic check to make sure typeahead's JS only gets initialized once
1 parent 05d3589 commit f0b77ac

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/uikit-workshop/src/js/pattern-finder.js renamed to packages/uikit-workshop/src/scripts/components/pattern-finder.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,26 @@
88
*
99
*/
1010

11-
var patternFinder = {
11+
import { urlHandler } from '@pattern-lab/utils/url-handler';
12+
import $ from 'jquery';
13+
import Bloodhound from 'typeahead.js/dist/bloodhound.js';
14+
15+
export const patternFinder = {
1216
data: [],
1317
active: false,
1418

1519
init: function() {
16-
for (var patternType in patternPaths) {
17-
if (patternPaths.hasOwnProperty(patternType)) {
18-
for (var pattern in patternPaths[patternType]) {
20+
// don't init more than once.
21+
if (document.querySelectorAll('.pl-js-typeahead').length > 1) {
22+
return;
23+
}
24+
25+
for (var patternType in window.patternPaths) {
26+
if (window.patternPaths.hasOwnProperty(patternType)) {
27+
for (var pattern in window.patternPaths[patternType]) {
1928
var obj = {};
2029
obj.patternPartial = patternType + '-' + pattern;
21-
obj.patternPath = patternPaths[patternType][pattern];
30+
obj.patternPath = window.patternPaths[patternType][pattern];
2231
this.data.push(obj);
2332
}
2433
}

0 commit comments

Comments
 (0)