Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | 5x 5x 5x 5x 5x 5x 5x 58x 58x 58x 56x 56x 56x 140x 58x 58x 58x 58x 58x 58x 58x 58x 58x 39x 39x 39x 111x 111x 2x 2x 2x 109x 37x 4x 4x 3x 3x 3x 34x 34x 2x 32x 32x 1x 31x 22x 22x 22x 9x 3x 3x 3x 3x 6x 3x 3x 58x 56x 56x 56x 56x 57x 6x 2x 4x 9x 3x 3x 2x 2x 2x 4x 4x 4x 1x 3x 3x 3x 33x 33x 24x 24x 24x 5x 5x 19x 16x 3x 3x 21x 6x 6x 4x 4x 4x 4x 5x 4x 1x 5x 2x 6x 6x 6x 6x 6x 4x 6x 5x 6x 4x 4x 4x 4x 4x 3x 4x 3x 2x 3x 4x 4x 4x 4x 4x 4x 4x 3x 4x 3x 2x 3x 4x 4x 4x 4x 4x 6x 8x 8x 8x 8x 8x 8x 3x 8x 3x | import { PictureLightboxService } from '../../../../services/pictures/picture-lightbox.service';
import { DOCUMENT } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
inject,
Input,
OnDestroy,
OnInit,
ViewEncapsulation,
} from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { LoggerService, NotificationService, WINDOW } from '@drevo-web/core';
/**
* State interface for managing interactive content visibility
* TODO: Remove when migrating wiki formatter to Angular
*/
interface ContentInteractionState {
commentsExpanded: boolean;
rusVisible: boolean;
cslVisible: boolean;
}
/**
* Component for rendering article content with internal link handling.
*
* This component:
* - Renders HTML content safely using innerHTML
* - Intercepts clicks on internal links and navigates using Angular Router
* - Provides styling for article content without ng-deep
* - Preserves id and name attributes for anchor navigation
*
* Uses ViewEncapsulation.None to allow styling of dynamically injected HTML
* without requiring ::ng-deep.
*
* @example
* ```html
* <app-article-content [content]="article.content" />
* ```
*/
@Component({
selector: 'app-article-content',
templateUrl: './article-content.component.html',
styleUrl: './article-content.component.scss',
encapsulation: ViewEncapsulation.None, // TODO remove after Formatter implementing
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ArticleContentComponent implements OnInit, OnDestroy {
private _content = '';
private _sanitizedContent: SafeHtml = '';
/**
* State for managing interactive content visibility (comments, translations)
* TODO: Remove when migrating wiki formatter to Angular
*/
private interactionState: ContentInteractionState = {
commentsExpanded: true,
rusVisible: true,
cslVisible: true,
};
/**
* HTML content to render
*/
@Input()
set content(value: string) {
this._content = value;
// Convert onclick="javascript:..." to data-onclick before sanitizing
const processedValue = this.preprocessContent(value);
this._sanitizedContent = this.sanitizer.bypassSecurityTrustHtml(processedValue);
}
get content(): string {
return this._content;
}
get sanitizedContent(): SafeHtml {
return this._sanitizedContent;
}
private readonly elementRef = inject(ElementRef<HTMLElement>);
private readonly document = inject(DOCUMENT);
private readonly window = inject(WINDOW);
private readonly router = inject(Router);
private readonly sanitizer = inject(DomSanitizer);
private readonly logger = inject(LoggerService).withContext('ArticleContent');
private readonly notification = inject(NotificationService);
private readonly pictureLightboxService = inject(PictureLightboxService);
private readonly clickHandler = (event: MouseEvent): void => {
const target = event.target as HTMLElement;
// Check for data-onclick attribute on clicked element or its parents
let element: HTMLElement | null = target;
while (element && element !== this.elementRef.nativeElement) {
const dataOnclick = element.getAttribute('data-onclick');
if (dataOnclick && this.isJavaScriptProtocol(dataOnclick)) {
event.preventDefault();
this.executeJavaScriptAction(dataOnclick);
return;
}
element = element.parentElement;
}
// Check for picture click inside .pic container
if (target.closest('.pic')) {
const pictureId = this.extractPictureId(target);
if (pictureId !== undefined) {
event.preventDefault();
this.pictureLightboxService.open(pictureId);
return;
}
}
// Then check for anchor links
const anchor = target.closest('a');
if (!anchor) {
return;
}
const href = anchor.getAttribute('href');
if (!href) {
return;
}
// Handle javascript: protocol links (legacy interactive features)
if (this.isJavaScriptProtocol(href)) {
event.preventDefault();
this.executeJavaScriptAction(href);
return;
}
// Handle anchor links (hash-only links like #section-id)
if (this.isAnchorLink(href)) {
event.preventDefault();
const anchorId = href.substring(1); // Remove '#'
this.scrollToAnchor(anchorId);
return;
}
// Only handle internal links (starting with /)
// Skip external links and special protocols
if (this.isInternalLink(href)) {
event.preventDefault();
this.router.navigateByUrl(href);
}
};
ngOnInit(): void {
this.elementRef.nativeElement.addEventListener('click', this.clickHandler);
}
/**
* Preprocess HTML content:
* - Remove elements with class="map" and their content
* - Convert onclick="javascript:..." to data-onclick
* This prevents browser from trying to execute undefined functions
* Uses regex to work in both browser and SSR contexts
*/
private preprocessContent(html: string): string {
// Remove all elements with class="map" and their content
let processed = this.removeMapElements(html);
// Convert onclick to data-onclick
processed = processed.replace(/\s+onclick=(["'])(javascript:[\s\S]*?)\1/gi, ' data-onclick=$1$2$1');
return processed;
}
/**
* Remove all HTML elements with class="map" and their content
*/
private removeMapElements(html: string): string {
// Remove paired tags like <div class="map">...</div>
// This regex matches opening tag with class="map", content, and closing tag
return html.replace(/<(\w+)[^>]*\sclass="map"[^>]*>[\s\S]*?<\/\1>|<\w+[^>]*\sclass="map"[^>]*\/>/gi, '');
}
ngOnDestroy(): void {
this.elementRef.nativeElement.removeEventListener('click', this.clickHandler);
}
/**
* Check if the href is an internal link that should be handled by Angular Router
*/
private isInternalLink(href: string): boolean {
// Internal links start with /
if (!href.startsWith('/')) {
return false;
}
// Skip hash-only links
return !href.startsWith('/#');
}
/**
* Check if the href is an anchor link (hash-only link like #section-id)
*/
private isAnchorLink(href: string): boolean {
return href.startsWith('#') && href.length > 1;
}
/**
* Scroll to an element with the given anchor ID with smooth behavior
*/
private scrollToAnchor(anchorId: string): void {
// Find element by id or name attribute
const element =
this.document.getElementById(anchorId) || this.document.querySelector(`[name="${CSS.escape(anchorId)}"]`);
if (element) {
// Use native scrollIntoView for smooth scrolling
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
// Add to browser history with full path to enable back/forward navigation
const url = `${this.window?.location.pathname}${this.window?.location.search}#${anchorId}`;
this.window?.history.pushState(undefined, '', url);
}
}
/**
* Extract picture ID from anchor href within a .pic container.
* Expected href format: /pictures/{id} or /pictures/{id}.html
*/
private extractPictureId(target: HTMLElement): number | undefined {
const anchor = target.closest('a');
const href = anchor?.getAttribute('href');
if (!href) {
return undefined;
}
const match = /^\/pictures\/(\d+)(?:\.html)?$/.exec(href);
Iif (!match) {
return undefined;
}
return Number(match[1]);
}
// ========================================================================
// Legacy interactive features support (TODO: Remove after wiki formatter migration)
// ========================================================================
/**
* Check if string is a javascript: protocol (with normalization to prevent bypass)
*/
private isJavaScriptProtocol(value: string): boolean {
const normalized = value.trim().toLowerCase().replace(/\s+/g, '');
return (
normalized.startsWith('javascript:') || normalized.startsWith('data:') || normalized.startsWith('vbscript:')
);
}
/**
* Execute javascript: protocol action from legacy content
* @param value - The href or onclick attribute value (e.g., "javascript:toggleAll()")
*/
private executeJavaScriptAction(value: string): void {
// Extract action name and parameter using regex
// Supports: toggleAll(), toggleGroup('class'), gmap=googleMap();return false;
const matchWithParam = /^javascript:\s*(?:\w+=)?([a-zA-Z]+)\('([a-zA-Z0-9_-]+)'\)(?:;.*)?$/i.exec(value.trim());
const matchSimple = /^javascript:\s*(?:\w+=)?([a-zA-Z]+)(?:\(\))?(?:;.*)?$/i.exec(value.trim());
let action: string;
let param: string | undefined;
if (matchWithParam) {
action = matchWithParam[1];
param = matchWithParam[2];
} else if (matchSimple) {
action = matchSimple[1];
} else {
this.logger.warn('Invalid javascript action format', { value });
return;
}
switch (action) {
case 'toggleAll':
this.toggleAll();
break;
case 'toggleRus':
this.toggleRus();
break;
case 'toggleCsl':
this.toggleCsl();
break;
case 'toggleGroup':
if (param) {
this.toggleGroup(param);
} else {
this.logger.warn('toggleGroup requires a class name parameter', { value });
}
break;
case 'toggleYandexMap':
case 'googleMap':
this.showNotImplementedYet();
break;
default:
this.logger.warn('Unknown javascript action', {
action,
value,
});
}
}
/**
* Toggle visibility of all comments
* Mimics jQuery: toggleAll() function
*/
private toggleAll(): void {
const host = this.elementRef.nativeElement;
const comments = host.querySelectorAll('.cmnt');
const links = Array.from(host.querySelectorAll('.LinkComment')) as HTMLElement[];
// Check current state from first link
const isExpanded = links[0]?.textContent?.trim() === 'Свернуть';
// Update all toggle links
links.forEach(link => {
link.textContent = isExpanded ? 'Развернуть' : 'Свернуть';
});
// Toggle comments visibility
comments.forEach((comment: Element) => {
(comment as HTMLElement).style.display = isExpanded ? 'none' : '';
});
// Update state
this.interactionState.commentsExpanded = !isExpanded;
}
/**
* Toggle visibility of Russian translation
* Mimics jQuery: toggleRus() function
*/
private toggleRus(): void {
const host = this.elementRef.nativeElement;
const rusElements = Array.from(host.querySelectorAll('.BibleRus')) as HTMLElement[];
const cslElements = Array.from(host.querySelectorAll('.BibleCsl')) as HTMLElement[];
// Toggle Russian elements
const willBeHidden = rusElements[0]?.style.display !== 'none';
rusElements.forEach(el => {
el.style.display = willBeHidden ? 'none' : '';
});
// If hiding Russian, ensure Church Slavonic is visible
if (willBeHidden) {
cslElements.forEach(el => {
el.style.display = '';
});
this.interactionState.cslVisible = true;
}
// Update state and links
this.interactionState.rusVisible = !willBeHidden;
this.updateBibleLinks();
}
/**
* Toggle visibility of Church Slavonic translation
* Mimics jQuery: toggleCsl() function
*/
private toggleCsl(): void {
const host = this.elementRef.nativeElement;
const cslElements = Array.from(host.querySelectorAll('.BibleCsl')) as HTMLElement[];
const rusElements = Array.from(host.querySelectorAll('.BibleRus')) as HTMLElement[];
// Toggle Church Slavonic elements
const willBeHidden = cslElements[0]?.style.display !== 'none';
cslElements.forEach(el => {
el.style.display = willBeHidden ? 'none' : '';
});
// If hiding Church Slavonic, ensure Russian is visible
if (willBeHidden) {
rusElements.forEach(el => {
el.style.display = '';
});
this.interactionState.rusVisible = true;
}
// Update state and links
this.interactionState.cslVisible = !willBeHidden;
this.updateBibleLinks();
}
/**
* Toggle visibility of elements by class name
* Mimics jQuery: toggleGroup(cl) function
*/
private toggleGroup(className: string): void {
const host = this.elementRef.nativeElement;
const elements = Array.from(host.querySelectorAll(`.${CSS.escape(className)}`)) as HTMLElement[];
elements.forEach(el => {
el.style.display = el.style.display === 'none' ? '' : 'none';
});
}
/**
* Update text of Bible translation toggle links
* Mimics jQuery: checkBibleLinks() function
*/
private updateBibleLinks(): void {
const host = this.elementRef.nativeElement;
const rusLinks = Array.from(host.querySelectorAll('.toggleRus')) as HTMLElement[];
const cslLinks = Array.from(host.querySelectorAll('.toggleCsl')) as HTMLElement[];
const rusText = this.interactionState.rusVisible ? 'Скрыть русский перевод' : 'Показать русский перевод';
const cslText = this.interactionState.cslVisible
? 'Скрыть церковнославянский перевод'
: 'Показать церковнославянский перевод';
rusLinks.forEach(link => {
link.textContent = rusText;
});
cslLinks.forEach(link => {
link.textContent = cslText;
});
}
private showNotImplementedYet(): void {
this.notification.info('Функция еще не реализована');
}
}
|