From 956115f696f64c805f3a316c9439d6fcac721ff4 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Mon, 11 Sep 2023 14:59:54 -0700 Subject: [PATCH] Move highlightAndScroll to dom.ts --- .../project-authoring.component.ts | 24 ++----------------- src/assets/wise5/common/dom/dom.ts | 18 ++++++++++++++ src/messages.xlf | 4 ++-- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.ts b/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.ts index 71b63dc7b2d..55a65b6e929 100644 --- a/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.ts +++ b/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.ts @@ -3,11 +3,10 @@ import { ConfigService } from '../../services/configService'; import { DeleteNodeService } from '../../services/deleteNodeService'; import { TeacherProjectService } from '../../services/teacherProjectService'; import { TeacherDataService } from '../../services/teacherDataService'; -import * as $ from 'jquery'; import { Subscription, filter } from 'rxjs'; import { Message } from '@stomp/stompjs'; import { RxStomp } from '@stomp/rx-stomp'; -import { temporarilyHighlightElement } from '../../common/dom/dom'; +import { highlightNodesAndScroll } from '../../common/dom/dom'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; @Component({ @@ -40,7 +39,7 @@ export class ProjectAuthoringComponent { this.subscriptions.add( this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe(() => { this.updateShowProjectView(); - this.temporarilyHighlightNewNodes(history.state.newNodes); + highlightNodesAndScroll(history.state.newNodes); }) ); } @@ -214,25 +213,6 @@ export class ProjectAuthoringComponent { ); } - /** - * Temporarily highlight the new nodes to draw attention to them - * @param newNodes the new nodes to highlight - */ - private temporarilyHighlightNewNodes(newNodes = []): void { - if (newNodes.length > 0) { - setTimeout(() => { - newNodes.forEach((newNode) => temporarilyHighlightElement(newNode.id)); - const firstNodeElementAdded = $('#' + newNodes[0].id); - $('#content').animate( - { - scrollTop: firstNodeElementAdded.prop('offsetTop') - 60 - }, - 1000 - ); - }); - } - } - protected getStepBackgroundColor(nodeId: string): string { return this.projectService.getBackgroundColor(nodeId); } diff --git a/src/assets/wise5/common/dom/dom.ts b/src/assets/wise5/common/dom/dom.ts index 8c28807b9a3..4739803a050 100644 --- a/src/assets/wise5/common/dom/dom.ts +++ b/src/assets/wise5/common/dom/dom.ts @@ -31,3 +31,21 @@ export function temporarilyHighlightElement(id: string, duration: number = 1000) }, 2000); }, duration); } + +/** + * Temporarily highlight the nodes and scroll to the first node to draw attention to them + * @param nodes the nodes to highlight + */ +export function highlightNodesAndScroll(nodes = []): void { + if (nodes.length > 0) { + setTimeout(() => { + nodes.forEach((node) => temporarilyHighlightElement(node.id)); + $('#content').animate( + { + scrollTop: $('#' + nodes[0].id).prop('offsetTop') - 60 + }, + 1000 + ); + }); + } +} diff --git a/src/messages.xlf b/src/messages.xlf index 0bd4267c218..896b4181760 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -11991,14 +11991,14 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Are you sure you want to delete the selected item? src/assets/wise5/authoringTool/project-authoring/project-authoring.component.ts - 132 + 131 Are you sure you want to delete the selected items? src/assets/wise5/authoringTool/project-authoring/project-authoring.component.ts - 133 + 132