diff options
Diffstat (limited to 'client/src/app/shared/shared-custom-markup/custom-markup.service.ts')
-rw-r--r-- | client/src/app/shared/shared-custom-markup/custom-markup.service.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-custom-markup/custom-markup.service.ts b/client/src/app/shared/shared-custom-markup/custom-markup.service.ts index ffaf15710..09414da95 100644 --- a/client/src/app/shared/shared-custom-markup/custom-markup.service.ts +++ b/client/src/app/shared/shared-custom-markup/custom-markup.service.ts | |||
@@ -1,12 +1,14 @@ | |||
1 | import { ComponentRef, Injectable } from '@angular/core' | 1 | import { ComponentRef, Injectable } from '@angular/core' |
2 | import { MarkdownService } from '@app/core' | 2 | import { MarkdownService } from '@app/core' |
3 | import { | 3 | import { |
4 | ButtonMarkupData, | ||
4 | ChannelMiniatureMarkupData, | 5 | ChannelMiniatureMarkupData, |
5 | EmbedMarkupData, | 6 | EmbedMarkupData, |
6 | PlaylistMiniatureMarkupData, | 7 | PlaylistMiniatureMarkupData, |
7 | VideoMiniatureMarkupData, | 8 | VideoMiniatureMarkupData, |
8 | VideosListMarkupData | 9 | VideosListMarkupData |
9 | } from '@shared/models' | 10 | } from '@shared/models' |
11 | import { ButtonMarkupComponent } from './button-markup.component' | ||
10 | import { ChannelMiniatureMarkupComponent } from './channel-miniature-markup.component' | 12 | import { ChannelMiniatureMarkupComponent } from './channel-miniature-markup.component' |
11 | import { DynamicElementService } from './dynamic-element.service' | 13 | import { DynamicElementService } from './dynamic-element.service' |
12 | import { EmbedMarkupComponent } from './embed-markup.component' | 14 | import { EmbedMarkupComponent } from './embed-markup.component' |
@@ -19,6 +21,7 @@ type BuilderFunction = (el: HTMLElement) => ComponentRef<any> | |||
19 | @Injectable() | 21 | @Injectable() |
20 | export class CustomMarkupService { | 22 | export class CustomMarkupService { |
21 | private builders: { [ selector: string ]: BuilderFunction } = { | 23 | private builders: { [ selector: string ]: BuilderFunction } = { |
24 | 'peertube-button': el => this.buttonBuilder(el), | ||
22 | 'peertube-video-embed': el => this.embedBuilder(el, 'video'), | 25 | 'peertube-video-embed': el => this.embedBuilder(el, 'video'), |
23 | 'peertube-playlist-embed': el => this.embedBuilder(el, 'playlist'), | 26 | 'peertube-playlist-embed': el => this.embedBuilder(el, 'playlist'), |
24 | 'peertube-video-miniature': el => this.videoMiniatureBuilder(el), | 27 | 'peertube-video-miniature': el => this.videoMiniatureBuilder(el), |
@@ -98,6 +101,21 @@ export class CustomMarkupService { | |||
98 | return component | 101 | return component |
99 | } | 102 | } |
100 | 103 | ||
104 | private buttonBuilder (el: HTMLElement) { | ||
105 | const data = el.dataset as ButtonMarkupData | ||
106 | const component = this.dynamicElementService.createElement(ButtonMarkupComponent) | ||
107 | |||
108 | const model = { | ||
109 | theme: data.theme, | ||
110 | href: data.href, | ||
111 | label: data.label, | ||
112 | blankTarget: this.buildBoolean(data.blankTarget) | ||
113 | } | ||
114 | this.dynamicElementService.setModel(component, model) | ||
115 | |||
116 | return component | ||
117 | } | ||
118 | |||
101 | private videosListBuilder (el: HTMLElement) { | 119 | private videosListBuilder (el: HTMLElement) { |
102 | const data = el.dataset as VideosListMarkupData | 120 | const data = el.dataset as VideosListMarkupData |
103 | const component = this.dynamicElementService.createElement(VideosListMarkupComponent) | 121 | const component = this.dynamicElementService.createElement(VideosListMarkupComponent) |
@@ -122,6 +140,13 @@ export class CustomMarkupService { | |||
122 | return parseInt(value, 10) | 140 | return parseInt(value, 10) |
123 | } | 141 | } |
124 | 142 | ||
143 | private buildBoolean (value: string) { | ||
144 | if (value === 'true') return true | ||
145 | if (value === 'false') return false | ||
146 | |||
147 | return undefined | ||
148 | } | ||
149 | |||
125 | private buildArrayNumber (value: string) { | 150 | private buildArrayNumber (value: string) { |
126 | if (!value) return undefined | 151 | if (!value) return undefined |
127 | 152 | ||