Skip to content

Commit

Permalink
Pre commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hieu Nguyen Dang committed May 8, 2024
1 parent 8bfac25 commit 63d65bb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
const equations = Array.from(container.querySelectorAll('.filter_mathjaxloader_equation'));
equations.forEach((node) => {
that.window.MathJax.Hub.Queue(['Typeset', that.window.MathJax.Hub, node], [that.fixUseUrls, node]);
that.window.MathJax.Hub.Queue([(node: Element) => {
// The notifyFilterContentRenderingComplete event takes an Array of NodeElements or a NodeList.
// We cannot create a NodeList, so we use an HTMLElement[].
CoreEvents.trigger(CoreEvents.FILTER_CONTENT_RENDERING_COMPLETE, {
node,
}, CoreSites.getCurrentSiteId());
}, node]);
});

// Set the delay back to normal after processing.
Expand Down
71 changes: 66 additions & 5 deletions src/addons/qtype/ddwtos/classes/ddwtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { CoreDirectivesRegistry } from '@singletons/directives-registry';
import { CoreCoordinates, CoreDom } from '@singletons/dom';
import { CoreEventObserver } from '@singletons/events';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreLogger } from '@singletons/logger';
import { AddonModQuizDdwtosQuestionData } from '../component/ddwtos';

Expand Down Expand Up @@ -210,6 +210,63 @@ export class AddonQtypeDdwtosQuestion {
this.resizeListener = CoreDom.onWindowResize(() => {
this.positionDragItems();
});


Check failure on line 214 in src/addons/qtype/ddwtos/classes/ddwtos.ts

View workflow job for this annotation

GitHub Actions / test

More than 1 blank line not allowed
CoreEvents.on(CoreEvents.FILTER_CONTENT_RENDERING_COMPLETE, (node: { node: HTMLElement }) => {
let currentFilteredItem = (node.node) as HTMLElement;
const parentIsDD = (currentFilteredItem?.parentNode as HTMLElement)?.closest('span')?.classList.contains('placed') ||
(currentFilteredItem?.parentNode as HTMLElement)?.closest('span')?.classList.contains('draghome');
const isDD: boolean = currentFilteredItem.classList.contains('placed') || currentFilteredItem.classList.contains('draghome');

Check failure on line 219 in src/addons/qtype/ddwtos/classes/ddwtos.ts

View workflow job for this annotation

GitHub Actions / test

This line has a length of 137. Maximum allowed is 132
if (!parentIsDD && !isDD) {
return;
}
if (parentIsDD) {
currentFilteredItem = (currentFilteredItem?.parentNode as HTMLElement)?.closest('span') as HTMLElement;
}
const root = this.container;
if (!root.contains(currentFilteredItem)) {
// If the DD item doesn't belong to this question
// In case we have multiple questions in the same page.
return;
}
const group = this.getGroup(currentFilteredItem),

Check failure on line 232 in src/addons/qtype/ddwtos/classes/ddwtos.ts

View workflow job for this annotation

GitHub Actions / test

Split 'const' declarations into multiple statements
choice = this.getChoice(currentFilteredItem);

let listOfModifiedDragDrop: Element[] = [];

Check failure on line 235 in src/addons/qtype/ddwtos/classes/ddwtos.ts

View workflow job for this annotation

GitHub Actions / test

'listOfModifiedDragDrop' is never reassigned. Use 'const' instead
const cloneElement = currentFilteredItem.cloneNode(true) as HTMLElement;
const nodeList = root.querySelectorAll('.addon-qtype-ddwtos-container .group' + group + '.choice' + choice);
const that = this;

Check failure on line 238 in src/addons/qtype/ddwtos/classes/ddwtos.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected aliasing of 'this' to local variable
nodeList.forEach(function(node) {
// Same modified item, skip it.
if (node === currentFilteredItem) {
return;
}
const originalClass = (node as HTMLElement).getAttribute('class');
const originalStyle = (node as HTMLElement).getAttribute('style');
// We want to keep all the handler and event for filtered item, so using clone is the only choice.
const filteredDragDropClone = currentFilteredItem.cloneNode(true) as HTMLElement;
// Replace the class and style of the drag drop item we want to replace for the clone.
if (originalClass !== null) {
filteredDragDropClone.setAttribute('class', originalClass);
}
if (originalStyle !== null) {
filteredDragDropClone.setAttribute('style', originalStyle);
}
if (!that.readOnly) {
that.makeDraggable(cloneElement);
}
// Insert into DOM.
if (node.parentNode !== null) {
node.parentNode.insertBefore(filteredDragDropClone, node);
}
// Add the item has been replaced to a list so we can remove it later.
listOfModifiedDragDrop.push(node);
});
listOfModifiedDragDrop.map(function(node) {
node.remove();
});

});
}

/**
Expand Down Expand Up @@ -327,7 +384,11 @@ export class AddonQtypeDdwtosQuestion {
protected padToWidthHeight(node: HTMLElement, width: number, height: number): void {
node.style.width = width + 'px';
node.style.height = height + 'px';
// Originally lineHeight was set as height to center the text but it comes on too height lines on multiline elements.

// // Make an elements alignment.
// node.style.lineHeight = height + 'px';
// node.style.textAlign = 'center';
// node.style.verticalAlign ='middle';
}

/**
Expand Down Expand Up @@ -480,9 +541,9 @@ export class AddonQtypeDdwtosQuestion {
return;
}

groupItems.forEach((item) => {
item.innerHTML = CoreTextUtils.decodeHTML(item.innerHTML);
});
// groupItems.forEach((item) => {
// item.innerHTML = CoreTextUtils.decodeHTML(item.innerHTML);
// });

// Wait to render in order to calculate size.
if (groupItems[0].parentElement) {
Expand Down
2 changes: 1 addition & 1 deletion src/addons/qtype/ddwtos/component/addon-qtype-ddwtos.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[contextInstanceId]="contextInstanceId" [courseId]="courseId" #questiontext (afterRender)="textRendered()" />

<core-format-text *ngIf="question.answers" [component]="component" [componentId]="componentId" [text]="question.answers"
[filter]="false" (afterRender)="answersRendered()" />
[contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" (afterRender)="answersRendered()" />

<div class="drags"></div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/core/singletons/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class CoreEvents {
static readonly COMPLETE_REQUIRED_PROFILE_DATA_FINISHED = 'complete_required_profile_data_finished';
static readonly MAIN_HOME_LOADED = 'main_home_loaded';
static readonly FULL_SCREEN_CHANGED = 'full_screen_changed';
static readonly FILTER_CONTENT_RENDERING_COMPLETE = 'core_filters_content_rendering_complete';

protected static logger = CoreLogger.getInstance('CoreEvents');
protected static observables: { [eventName: string]: Subject<unknown> } = {};
Expand Down

0 comments on commit 63d65bb

Please sign in to comment.