Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 163b8e3

Browse files
committed
export TEMPLATE_TYPES
1 parent 7cd08c4 commit 163b8e3

12 files changed

+62
-28
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ Example callback function for `onAfterElementRendered`:
9191
const onAfterElementRendered = (element, template) => {
9292
// maniplate elements:
9393
switch (template.type) {
94-
case 'text':
94+
case JsonPollock.TEMPLATE_TYPES.TEXT:
9595
// add custom css class
9696
element.classList.add('my-ns-text');
9797
break;
98-
case 'link':
98+
case JsonPollock.TEMPLATE_TYPES.LINK:
9999
// edit inline style
100100
element.style.color = 'red';
101101
break;
102-
case 'map':
102+
case JsonPollock.TEMPLATE_TYPES.MAP:
103103
// prevent 'map' element to be rendered
104104
return null;
105105
...

dist/json-pollock.bundle.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-pollock.global.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-pollock.global.no_validation.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-pollock.js

+22-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-pollock.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-pollock.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/card_custom.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,26 @@
290290
const onAfterElementRendered = (element, template) => {
291291
console.log(element, template.type);
292292
switch (template.type) {
293-
case 'vertical':
293+
case JsonPollock.TEMPLATE_TYPES.VERTICAL:
294294
element.style = 'border-style:dashed;border-color:red;';
295295
break;
296-
case 'image':
296+
case JsonPollock.TEMPLATE_TYPES.IMAGE:
297297
element.firstElementChild.src = 'https://image.shutterstock.com/image-vector/hacked-glitched-abstract-digital-background-450w-761155144.jpg';
298298
break;
299-
case 'button':
299+
case JsonPollock.TEMPLATE_TYPES.BUTTON:
300300
element.firstElementChild.onclick = () => {
301301
alert('hacked on after render hook!');
302302
}
303303
break;
304-
case 'map':
304+
case JsonPollock.TEMPLATE_TYPES.MAP:
305305
element.classList.add('take-me-out');
306306
break;
307-
case 'text':
307+
case JsonPollock.TEMPLATE_TYPES.TEXT:
308308
const color = Math.trunc(Math.random() * 1000000);
309309
element.firstElementChild.style.color = `#${color}`;
310310
break;
311+
case JsonPollock.TEMPLATE_TYPES.HORIZONTAL:
312+
case JsonPollock.TEMPLATE_TYPES.CAROUSEL:
311313
default:
312314
// this will remove the element
313315
element = null;

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const registerAction = instance.registerAction.bind(instance);
1414
const unregisterAction = instance.unregisterAction.bind(instance);
1515
const unregisterAllActions = instance.unregisterAllActions.bind(instance);
1616
const version = '@@VERSION';
17+
const TEMPLATE_TYPES = JsonPollock.TEMPLATE_TYPES;
1718

1819
export {
1920
init,
@@ -22,4 +23,5 @@ export {
2223
unregisterAction,
2324
unregisterAllActions,
2425
version,
26+
TEMPLATE_TYPES,
2527
};

index.no_validation.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const registerAction = instance.registerAction.bind(instance);
1313
const unregisterAction = instance.unregisterAction.bind(instance);
1414
const unregisterAllActions = instance.unregisterAllActions.bind(instance);
1515
const version = '@@VERSION';
16+
const TEMPLATE_TYPES = JsonPollock.TEMPLATE_TYPES;
1617

1718
export {
1819
init,
@@ -21,4 +22,5 @@ export {
2122
unregisterAction,
2223
unregisterAllActions,
2324
version,
25+
TEMPLATE_TYPES,
2426
};

js/ElementRendererProvider.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ import Utils from './Utils';
55
const Events = require('Chronosjs/dist/min/Events');
66
/*eslint-enable */
77

8+
const TYPES = {
9+
TEXT: 'text',
10+
BUTTON: 'button',
11+
IMAGE: 'image',
12+
MAP: 'map',
13+
VERTICAL: 'vertical',
14+
HORIZONTAL: 'horizontal',
15+
CAROUSEL: 'carousel',
16+
};
17+
818
export default class ElementRendererProvider {
919

20+
static TYPES: Object = TYPES;
21+
1022
elements: Object;
1123
events: Events;
1224

@@ -17,7 +29,7 @@ export default class ElementRendererProvider {
1729
/*
1830
predefined renderes
1931
*/
20-
this.set('text', (config): HTMLElement => {
32+
this.set(TYPES.TEXT, (config): HTMLElement => {
2133
const divEl = document.createElement('div');
2234
const tooltip = config.tooltip ? Utils.escapeHtml(config.tooltip) : '';
2335
divEl.className = 'lp-json-pollock-element-text';
@@ -29,7 +41,7 @@ export default class ElementRendererProvider {
2941
return divEl;
3042
});
3143

32-
this.set('button', (config): HTMLElement => {
44+
this.set(TYPES.BUTTON, (config): HTMLElement => {
3345
const divEl = document.createElement('div');
3446
divEl.className = 'lp-json-pollock-element-button';
3547

@@ -58,7 +70,7 @@ export default class ElementRendererProvider {
5870
return divEl;
5971
});
6072

61-
this.set('image', (config): HTMLElement => {
73+
this.set(TYPES.IMAGE, (config): HTMLElement => {
6274
const divEl = document.createElement('div');
6375
divEl.className = 'lp-json-pollock-element-image loading';
6476

@@ -101,7 +113,7 @@ export default class ElementRendererProvider {
101113
return divEl;
102114
});
103115

104-
this.set('map', (config): HTMLElement => {
116+
this.set(TYPES.MAP, (config): HTMLElement => {
105117
const divEl = document.createElement('div');
106118
divEl.className = 'lp-json-pollock-element-map';
107119

@@ -125,13 +137,13 @@ export default class ElementRendererProvider {
125137
return divEl;
126138
});
127139

128-
this.set('vertical', (): HTMLElement => {
140+
this.set(TYPES.VERTICAL, (): HTMLElement => {
129141
const divEl = document.createElement('div');
130142
divEl.className = 'lp-json-pollock-layout lp-json-pollock-layout-vertical';
131143
return divEl;
132144
});
133145

134-
this.set('carousel', (config): HTMLElement => {
146+
this.set(TYPES.CAROUSEL, (config): HTMLElement => {
135147
const defaultPadding = 0;
136148
const padding = config.padding || defaultPadding;
137149
const CARD_DEFAULT_WIDTH = 180;
@@ -270,7 +282,7 @@ export default class ElementRendererProvider {
270282
return divCarouselWrapper;
271283
});
272284

273-
this.set('horizontal', (): HTMLElement => {
285+
this.set(TYPES.HORIZONTAL, (): HTMLElement => {
274286
const divEl = document.createElement('div');
275287
divEl.className = 'lp-json-pollock-layout lp-json-pollock-layout-horizontal';
276288
(divEl: any).afterRender = () => {

js/JsonPollock.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class JsonPollockError extends Error {
1818

1919
export default class JsonPollock {
2020

21+
static TEMPLATE_TYPES: Object = ElementRendererProvider.TYPES;
22+
2123
provider: ElementRendererProvider;
2224
events: Events;
2325
currentNumOfElements: number;

0 commit comments

Comments
 (0)