Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile 4587 #4133

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/addons/qtype/ddimageortext/classes/ddimageortext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { CoreDom } from '@singletons/dom';
import { CoreEventObserver } from '@singletons/events';
import { CoreLogger } from '@singletons/logger';
import { AddonModQuizDdImageOrTextQuestionData } from '../component/ddimageortext';
import { CoreLinkDirective } from '@directives/link';
import { ElementRef } from '@angular/core';

/**
* Class to make a question of ddimageortext type work.
Expand Down Expand Up @@ -857,6 +859,12 @@ export class AddonQtypeDdImageOrTextQuestionDocStructure {
divDrag.setAttribute('dragitemno', String(dragItemNo));
divDrag.setAttribute('tabindex', '0');

Array.from(divDrag.querySelectorAll('a')).forEach((anchor) => {
const linkDir = new CoreLinkDirective(new ElementRef(anchor));
linkDir.capture = true;
linkDir.ngOnInit();
});

// Insert the new drag after the dragHome.
dragHome.parentElement?.insertBefore(divDrag, dragHome.nextSibling);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ion-item>
<div class="fake-ion-item ion-text-wrap" [class.readonly]="question.readOnly" [hidden]="!question.loaded">
<core-format-text *ngIf="question.ddArea" [adaptImg]="false" [component]="component" [componentId]="componentId"
[text]="question.ddArea" [filter]="false" (afterRender)="ddAreaRendered()" />
[text]="question.ddArea" [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="courseId"
(afterRender)="ddAreaRendered()" />
</div>
</div>
19 changes: 19 additions & 0 deletions src/addons/qtype/ddmarker/classes/ddmarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { AddonQtypeDdMarkerGraphicsApi } from './graphics_api';
import { CoreUtils } from '@services/utils/utils';
import { CoreDirectivesRegistry } from '@singletons/directives-registry';
import { CoreExternalContentDirective } from '@directives/external-content';
import { CoreLinkDirective } from '@directives/link';
import { ElementRef } from '@angular/core';

/**
* Class to make a question of ddmarker type work.
Expand Down Expand Up @@ -97,6 +99,8 @@ export class AddonQtypeDdMarkerQuestion {
drag.classList.remove('dragplaceholder'); // In case it has it.
dragHome.classList.add('dragplaceholder');

this.treatAnchors(drag);

// Insert the new drag after the dragHome.
dragHome.parentElement?.insertBefore(drag, dragHome.nextSibling);
if (!this.readOnly) {
Expand Down Expand Up @@ -252,6 +256,7 @@ export class AddonQtypeDdMarkerQuestion {
// Marker text already exists. Update it or remove it if empty.
if (markerText !== '') {
existingMarkerText.innerHTML = markerText;
this.treatAnchors(existingMarkerText);
} else {
existingMarkerText.remove();
}
Expand All @@ -262,6 +267,7 @@ export class AddonQtypeDdMarkerQuestion {

span.className = classNames;
span.innerHTML = markerText;
this.treatAnchors(span);

markerTexts.appendChild(span);
}
Expand Down Expand Up @@ -896,6 +902,19 @@ export class AddonQtypeDdMarkerQuestion {
}
}

/**
* Treat anchors inside an element, adding the core-link directive.
*
* @param el Element to treat.
*/
protected treatAnchors(el: HTMLElement): void {
Array.from(el.querySelectorAll('a')).forEach((anchor) => {
const linkDir = new CoreLinkDirective(new ElementRef(anchor));
linkDir.capture = true;
linkDir.ngOnInit();
});
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ion-item>
<div class="fake-ion-item ion-text-wrap" [hidden]="!question.loaded">
<core-format-text *ngIf="question.ddArea" [adaptImg]="false" [component]="component" [componentId]="componentId"
[text]="question.ddArea" [filter]="false" (afterRender)="ddAreaRendered()" />
[text]="question.ddArea" [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="courseId"
(afterRender)="ddAreaRendered()" />
</div>
</div>
4 changes: 4 additions & 0 deletions src/addons/qtype/ddmarker/component/ddmarker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ core-format-text ::ng-deep {
user-select: none;
}

.d-none {
display: none;
}

.qtext {
margin-bottom: 0.5em;
display: block;
Expand Down
9 changes: 9 additions & 0 deletions src/addons/qtype/ddwtos/classes/ddwtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { CoreEventObserver } from '@singletons/events';
import { CoreLogger } from '@singletons/logger';
import { AddonModQuizDdwtosQuestionData } from '../component/ddwtos';
import { CoreWait } from '@singletons/wait';
import { CoreLinkDirective } from '@directives/link';
import { ElementRef } from '@angular/core';

/**
* Class to make a question of ddwtos type work.
Expand Down Expand Up @@ -69,6 +71,13 @@ export class AddonQtypeDdwtosQuestion {
drag.style.visibility = 'visible';
drag.style.position = 'absolute';

Array.from(drag.querySelectorAll('a')).forEach((anchor) => {
// Cloning the item doesn't clone its directives. Add core-link to the anchors.
const linkDir = new CoreLinkDirective(new ElementRef(anchor));
linkDir.capture = true;
linkDir.ngOnInit();
});

const container = this.container.querySelector(this.selectors.dragContainer());
container?.appendChild(drag);

Expand Down
5 changes: 2 additions & 3 deletions src/addons/qtype/ddwtos/component/addon-qtype-ddwtos.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
[contextInstanceId]="contextInstanceId" [courseId]="courseId" #questiontext (afterRender)="textRendered()" />

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

<div class="drags"></div>
[contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="courseId"
(afterRender)="answersRendered()" />
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions src/addons/qtype/ddwtos/component/ddwtos.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ core-format-text ::ng-deep, .drags ::ng-deep {
}

.draghome {
margin-bottom: 1em;
max-width: calc(100%);
}

Expand All @@ -47,6 +46,10 @@ core-format-text ::ng-deep, .drags ::ng-deep {
white-space: normal;
overflow: visible;
word-wrap: break-word;
margin-bottom: 1em;
border-radius: 5px;
line-height: 25px;
cursor: var(--cursor);
}
.draghome, .drag.unplaced{
border: 1px solid var(--core-dd-question-border);
Expand All @@ -56,9 +59,6 @@ core-format-text ::ng-deep, .drags ::ng-deep {
}
.drag {
z-index: 2;
border-radius: 5px;
line-height: 25px;
cursor: var(--cursor);
}
.drag.selected,
.drop.selected {
Expand Down
4 changes: 3 additions & 1 deletion src/addons/qtype/ddwtos/component/ddwtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class AddonQtypeDdwtosComponent extends CoreQuestionBaseComponent<AddonMo
}

this.question.readOnly = answerContainer.classList.contains('readonly');
this.question.answers = answerContainer.outerHTML;
// Add the drags container inside the answers so it's rendered inside core-format-text,
// otherwise some styles could be different between the drag homes and the draggables.
this.question.answers = answerContainer.outerHTML + '<div class="drags"></div>';

// Get the inputs where the answers will be stored and add them to the question text.
const inputEls = Array.from(
Expand Down
6 changes: 2 additions & 4 deletions src/core/directives/format-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
Inject,
ChangeDetectorRef,
} from '@angular/core';
import { IonContent } from '@ionic/angular';

import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
Expand Down Expand Up @@ -104,7 +103,6 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec

constructor(
element: ElementRef,
@Optional() protected content: IonContent,
protected viewContainerRef: ViewContainerRef,
@Optional() @Inject(CORE_REFRESH_CONTEXT) protected refreshContext?: CoreRefreshContext,
) {
Expand Down Expand Up @@ -503,8 +501,8 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
return;
}

// Angular 2 doesn't let adding directives dynamically. Create the CoreLinkDirective manually.
const linkDir = new CoreLinkDirective(new ElementRef(anchor), this.content);
// Angular doesn't let adding directives dynamically. Create the CoreLinkDirective manually.
const linkDir = new CoreLinkDirective(new ElementRef(anchor));
linkDir.capture = this.captureLinks ?? true;
linkDir.inApp = this.openLinksInApp;
linkDir.ngOnInit();
Expand Down
4 changes: 1 addition & 3 deletions src/core/directives/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Directive, Input, OnInit, ElementRef, Optional, SecurityContext } from '@angular/core';
import { Directive, Input, OnInit, ElementRef, SecurityContext } from '@angular/core';
import { SafeUrl } from '@angular/platform-browser';
import { IonContent } from '@ionic/angular';

import { CoreFileHelper } from '@services/file-helper';
import { CoreSites } from '@services/sites';
Expand Down Expand Up @@ -47,7 +46,6 @@ export class CoreLinkDirective implements OnInit {

constructor(
element: ElementRef,
@Optional() protected content: IonContent,
) {
this.element = element.nativeElement;
}
Expand Down