Skip to content

Commit b33d0cd

Browse files
committed
refactor: refactor pattern name logic out of styleguide.js's jQuery soup
1 parent f07ea6f commit b33d0cd

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

packages/uikit-workshop/src/scripts/components/styleguide.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import $ from 'jquery';
66
import Mousetrap from 'mousetrap';
7-
import { urlHandler, DataSaver } from '../utils';
7+
import { urlHandler, DataSaver, patternName } from '../utils';
88

99
(function(w) {
1010
let sw = document.body.clientWidth; //Viewport Width
@@ -523,17 +523,8 @@ import { urlHandler, DataSaver } from '../utils';
523523
'//' +
524524
window.location.host +
525525
window.location.pathname.replace('index.html', '');
526-
let patternName =
527-
window.config.defaultPattern !== undefined &&
528-
typeof window.config.defaultPattern === 'string' &&
529-
window.config.defaultPattern.trim().length > 0
530-
? window.config.defaultPattern
531-
: 'all';
532526
let iFramePath =
533527
baseIframePath + 'styleguide/html/styleguide.html?' + Date.now();
534-
if (oGetVars.p !== undefined || oGetVars.pattern !== undefined) {
535-
patternName = oGetVars.p !== undefined ? oGetVars.p : oGetVars.pattern;
536-
}
537528

538529
if (patternName !== 'all') {
539530
const patternPath = urlHandler.getFileName(patternName);

packages/uikit-workshop/src/scripts/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { css } from './css';
77
export { extend } from './extend';
88
export { supportsShadowDom } from './supports-shadow-dom';
99
export { targetOrigin } from './get-target-origin';
10+
export { patternName } from './pattern-name';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { urlHandler } from '../utils';
2+
3+
let patternName = '';
4+
5+
if (window.config) {
6+
patternName =
7+
window.config.defaultPattern !== undefined &&
8+
typeof window.config.defaultPattern === 'string' &&
9+
window.config.defaultPattern.trim().length > 0
10+
? window.config.defaultPattern
11+
: 'all';
12+
13+
// get the request vars
14+
const oGetVars = urlHandler.getRequestVars();
15+
16+
if (oGetVars.p !== undefined || oGetVars.pattern !== undefined) {
17+
patternName = oGetVars.p !== undefined ? oGetVars.p : oGetVars.pattern;
18+
}
19+
}
20+
21+
export { patternName };

0 commit comments

Comments
 (0)