diff --git a/src/addon/qtype/ddmarker/component/addon-qtype-ddmarker.html b/src/addon/qtype/ddmarker/component/addon-qtype-ddmarker.html
index b94b17668..199abc85d 100644
--- a/src/addon/qtype/ddmarker/component/addon-qtype-ddmarker.html
+++ b/src/addon/qtype/ddmarker/component/addon-qtype-ddmarker.html
@@ -7,7 +7,7 @@
{{ 'core.question.howtodraganddrop' | translate }}
-
+
diff --git a/src/addon/qtype/ddmarker/component/ddmarker.ts b/src/addon/qtype/ddmarker/component/ddmarker.ts
index 345887738..518a8b885 100644
--- a/src/addon/qtype/ddmarker/component/ddmarker.ts
+++ b/src/addon/qtype/ddmarker/component/ddmarker.ts
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Component, OnInit, OnDestroy, Injector, ElementRef } from '@angular/core';
+import { Component, OnInit, OnDestroy, Injector, ElementRef, ViewChild } from '@angular/core';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreQuestionBaseComponent } from '@core/question/classes/base-question-component';
import { AddonQtypeDdMarkerQuestion } from '../classes/ddmarker';
@@ -25,6 +25,7 @@ import { AddonQtypeDdMarkerQuestion } from '../classes/ddmarker';
templateUrl: 'addon-qtype-ddmarker.html'
})
export class AddonQtypeDdMarkerComponent extends CoreQuestionBaseComponent implements OnInit, OnDestroy {
+ @ViewChild('questiontext') questionTextEl: ElementRef;
protected element: HTMLElement;
protected questionInstance: AddonQtypeDdMarkerQuestion;
@@ -87,9 +88,11 @@ export class AddonQtypeDdMarkerComponent extends CoreQuestionBaseComponent imple
*/
questionRendered(): void {
if (!this.destroyed) {
- // Create the instance.
- this.questionInstance = new AddonQtypeDdMarkerQuestion(this.loggerProvider, this.domUtils, this.textUtils, this.element,
- this.question, this.question.readOnly, this.dropZones);
+ this.domUtils.waitForImages(this.questionTextEl.nativeElement).then(() => {
+ // Create the instance.
+ this.questionInstance = new AddonQtypeDdMarkerQuestion(this.loggerProvider, this.domUtils, this.textUtils,
+ this.element, this.question, this.question.readOnly, this.dropZones);
+ });
}
}
diff --git a/src/addon/qtype/ddwtos/component/addon-qtype-ddwtos.html b/src/addon/qtype/ddwtos/component/addon-qtype-ddwtos.html
index fbe7bf186..67c15fdfd 100644
--- a/src/addon/qtype/ddwtos/component/addon-qtype-ddwtos.html
+++ b/src/addon/qtype/ddwtos/component/addon-qtype-ddwtos.html
@@ -1,10 +1,13 @@
-
+
+
+
+
{{ 'core.question.howtodraganddrop' | translate }}
-
+
diff --git a/src/addon/qtype/ddwtos/component/ddwtos.ts b/src/addon/qtype/ddwtos/component/ddwtos.ts
index 8e39b0a3c..80f97c38e 100644
--- a/src/addon/qtype/ddwtos/component/ddwtos.ts
+++ b/src/addon/qtype/ddwtos/component/ddwtos.ts
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Component, OnInit, OnDestroy, Injector, ElementRef } from '@angular/core';
+import { Component, OnInit, OnDestroy, Injector, ElementRef, ViewChild } from '@angular/core';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreQuestionBaseComponent } from '@core/question/classes/base-question-component';
import { AddonQtypeDdwtosQuestion } from '../classes/ddwtos';
@@ -25,6 +25,7 @@ import { AddonQtypeDdwtosQuestion } from '../classes/ddwtos';
templateUrl: 'addon-qtype-ddwtos.html'
})
export class AddonQtypeDdwtosComponent extends CoreQuestionBaseComponent implements OnInit, OnDestroy {
+ @ViewChild('questiontext') questionTextEl: ElementRef;
protected element: HTMLElement;
protected questionInstance: AddonQtypeDdwtosQuestion;
@@ -80,6 +81,8 @@ export class AddonQtypeDdwtosComponent extends CoreQuestionBaseComponent impleme
this.question.text += inputEl.outerHTML;
this.inputIds.push(inputEl.getAttribute('id'));
});
+
+ this.question.loaded = false;
}
/**
@@ -87,11 +90,15 @@ export class AddonQtypeDdwtosComponent extends CoreQuestionBaseComponent impleme
*/
questionRendered(): void {
if (!this.destroyed) {
- // Create the instance.
- this.questionInstance = new AddonQtypeDdwtosQuestion(this.loggerProvider, this.domUtils, this.element, this.question,
- this.question.readOnly, this.inputIds);
+ this.domUtils.waitForImages(this.questionTextEl.nativeElement).then(() => {
+ // Create the instance.
+ this.questionInstance = new AddonQtypeDdwtosQuestion(this.loggerProvider, this.domUtils, this.element,
+ this.question, this.question.readOnly, this.inputIds);
- this.questionHelper.treatCorrectnessIconsClicks(this.element, this.component, this.componentId);
+ this.questionHelper.treatCorrectnessIconsClicks(this.element, this.component, this.componentId);
+
+ this.question.loaded = true;
+ });
}
}
diff --git a/src/addon/qtype/ddwtos/ddwtos.module.ts b/src/addon/qtype/ddwtos/ddwtos.module.ts
index 00e0c1dbf..0508ddb5a 100644
--- a/src/addon/qtype/ddwtos/ddwtos.module.ts
+++ b/src/addon/qtype/ddwtos/ddwtos.module.ts
@@ -16,6 +16,7 @@ import { NgModule } from '@angular/core';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreQuestionDelegate } from '@core/question/providers/delegate';
+import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { AddonQtypeDdwtosHandler } from './providers/handler';
import { AddonQtypeDdwtosComponent } from './component/ddwtos';
@@ -27,6 +28,7 @@ import { AddonQtypeDdwtosComponent } from './component/ddwtos';
imports: [
IonicModule,
TranslateModule.forChild(),
+ CoreComponentsModule,
CoreDirectivesModule
],
providers: [
diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts
index ded8c96d9..817e88360 100644
--- a/src/directives/format-text.ts
+++ b/src/directives/format-text.ts
@@ -296,7 +296,7 @@ export class CoreFormatTextDirective implements OnChanges {
this.calculateHeight();
// Wait for images to load and calculate the height again if needed.
- this.waitForImages().then((hasImgToLoad) => {
+ this.domUtils.waitForImages(this.element).then((hasImgToLoad) => {
if (hasImgToLoad) {
this.calculateHeight();
}
@@ -628,39 +628,6 @@ export class CoreFormatTextDirective implements OnChanges {
this.iframeUtils.treatFrame(iframe);
}
- /**
- * Wait for images to load.
- *
- * @return {Promise} Promise resolved with a boolean: whether there was any image to load.
- */
- protected waitForImages(): Promise {
- const imgs = Array.from(this.element.querySelectorAll('img')),
- promises = [];
- let hasImgToLoad = false;
-
- imgs.forEach((img) => {
- if (img && !img.complete) {
- hasImgToLoad = true;
-
- // Wait for image to load or fail.
- promises.push(new Promise((resolve, reject): void => {
- const imgLoaded = (): void => {
- resolve();
- img.removeEventListener('loaded', imgLoaded);
- img.removeEventListener('error', imgLoaded);
- };
-
- img.addEventListener('load', imgLoaded);
- img.addEventListener('error', imgLoaded);
- }));
- }
- });
-
- return Promise.all(promises).then(() => {
- return hasImgToLoad;
- });
- }
-
/**
* Convenience function to extract YouTube Id to translate to embedded video.
* Based on http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url
diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts
index 361fabcd9..ccd28ddc3 100644
--- a/src/providers/utils/dom.ts
+++ b/src/providers/utils/dom.ts
@@ -1258,6 +1258,40 @@ export class CoreDomUtilsProvider {
}
+ /**
+ * Wait for images to load.
+ *
+ * @param {HTMLElement} element The element to search in.
+ * @return {Promise} Promise resolved with a boolean: whether there was any image to load.
+ */
+ waitForImages(element: HTMLElement): Promise {
+ const imgs = Array.from(element.querySelectorAll('img')),
+ promises = [];
+ let hasImgToLoad = false;
+
+ imgs.forEach((img) => {
+ if (img && !img.complete) {
+ hasImgToLoad = true;
+
+ // Wait for image to load or fail.
+ promises.push(new Promise((resolve, reject): void => {
+ const imgLoaded = (): void => {
+ resolve();
+ img.removeEventListener('load', imgLoaded);
+ img.removeEventListener('error', imgLoaded);
+ };
+
+ img.addEventListener('load', imgLoaded);
+ img.addEventListener('error', imgLoaded);
+ }));
+ }
+ });
+
+ return Promise.all(promises).then(() => {
+ return hasImgToLoad;
+ });
+ }
+
/**
* Wrap an HTMLElement with another element.
*