Skip to content

Commit 4193bfc

Browse files
authored
Merge pull request #4150 from crazyserver/MOBILE-4616
Mobile 4616
2 parents 976de68 + 00951b2 commit 4193bfc

File tree

168 files changed

+2024
-1390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+2024
-1390
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
cat circular-dependencies
7070
lines=$(cat circular-dependencies | wc -l)
7171
echo "Total circular dependencies: $lines"
72-
test $lines -eq 131
72+
test $lines -eq 130
7373
- name: JavaScript code compatibility
7474
run: |
7575
npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn"

src/addons/block/myoverview/components/myoverview/myoverview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { CoreBlockBaseComponent } from '@features/block/classes/base-block-compo
2929
import { CoreSite } from '@classes/sites/site';
3030
import { CoreUtils } from '@services/utils/utils';
3131
import { CoreDomUtils } from '@services/utils/dom';
32-
import { CoreTextUtils } from '@services/utils/text';
32+
import { CoreText } from '@singletons/text';
3333
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
3434
import { IonSearchbar } from '@ionic/angular';
3535
import { CoreNavigator } from '@services/navigator';
@@ -375,7 +375,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
375375
this.filters.show.custom = config?.displaygroupingcustomfield?.value == '1' && !!config?.customfieldsexport?.value;
376376

377377
this.filters.customFilters = this.filters.show.custom
378-
? CoreTextUtils.parseJSON(config?.customfieldsexport?.value || '[]', [])
378+
? CoreText.parseJSON(config?.customfieldsexport?.value || '[]', [])
379379
: [];
380380

381381
// Check if any selector is shown and not disabled.

src/addons/block/recentlyaccesseditems/components/recentlyaccesseditems/recentlyaccesseditems.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
AddonBlockRecentlyAccessedItems,
2020
AddonBlockRecentlyAccessedItemsItemCalculatedData,
2121
} from '../../services/recentlyaccesseditems';
22-
import { CoreTextUtils } from '@services/utils/text';
22+
import { CoreText } from '@singletons/text';
2323
import { CoreLoadings } from '@services/loadings';
2424
import { CoreUtils } from '@services/utils/utils';
2525
import { CoreSharedModule } from '@/core/shared.module';
@@ -92,7 +92,7 @@ export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseCompo
9292
e.preventDefault();
9393
e.stopPropagation();
9494

95-
const url = CoreTextUtils.decodeHTMLEntities(item.viewurl);
95+
const url = CoreText.decodeHTMLEntities(item.viewurl);
9696
const modal = await CoreLoadings.show();
9797

9898
try {

src/addons/block/timeline/components/events/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
1616
import { CoreSites } from '@services/sites';
1717
import { CoreLoadings } from '@services/loadings';
18-
import { CoreTextUtils } from '@services/utils/text';
18+
import { CoreText } from '@singletons/text';
1919
import { CoreEnrolledCourseDataWithOptions } from '@features/courses/services/courses-helper';
2020
import { AddonBlockTimelineDayEvents } from '@addons/block/timeline/classes/section';
2121
import { CoreSharedModule } from '@/core/shared.module';
@@ -64,7 +64,7 @@ export class AddonBlockTimelineEventsComponent implements OnInit {
6464
event.stopPropagation();
6565

6666
// Fix URL format.
67-
url = CoreTextUtils.decodeHTMLEntities(url);
67+
url = CoreText.decodeHTMLEntities(url);
6868

6969
const modal = await CoreLoadings.show();
7070

src/addons/blog/pages/index/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
2424
import { CoreNavigator } from '@services/navigator';
2525
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
2626
import { CoreDomUtils } from '@services/utils/dom';
27-
import { CoreTextUtils } from '@services/utils/text';
27+
import { CoreFileHelper } from '@services/file-helper';
2828
import { CoreUrl } from '@singletons/url';
2929
import { CoreUtils } from '@services/utils/utils';
3030
import { CoreArray } from '@singletons/array';
@@ -212,7 +212,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
212212
entry.contextInstanceId = entry.userid;
213213
}
214214

215-
entry.summary = CoreTextUtils.replacePluginfileUrls(entry.summary, entry.summaryfiles || []);
215+
entry.summary = CoreFileHelper.replacePluginfileUrls(entry.summary, entry.summaryfiles || []);
216216

217217
entry.user = await CoreUtils.ignoreErrors(CoreUser.getProfile(entry.userid, entry.courseid, true));
218218
});

src/addons/calendar/pages/event/event.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider }
2525
import { CoreNetwork } from '@services/network';
2626
import { CoreEventObserver, CoreEvents } from '@singletons/events';
2727
import { CoreDomUtils } from '@services/utils/dom';
28-
import { CoreTextUtils } from '@services/utils/text';
28+
import { CoreText } from '@singletons/text';
2929
import { CoreSites } from '@services/sites';
3030
import { CoreCourse } from '@features/course/services/course';
3131
import { CoreTimeUtils } from '@services/utils/time';
@@ -45,6 +45,7 @@ import { CoreConfig } from '@services/config';
4545
import { CoreToasts, ToastDuration } from '@services/toasts';
4646
import { CorePopovers } from '@services/popovers';
4747
import { CoreLoadings } from '@services/loadings';
48+
import { CoreUrl } from '@singletons/url';
4849

4950
/**
5051
* Page that displays a single calendar event.
@@ -288,8 +289,8 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
288289

289290
if (this.event.location) {
290291
// Build a link to open the address in maps.
291-
this.event.location = CoreTextUtils.decodeHTML(this.event.location);
292-
this.event.encodedLocation = CoreTextUtils.buildAddressURL(this.event.location);
292+
this.event.location = CoreText.decodeHTML(this.event.location);
293+
this.event.encodedLocation = CoreUrl.buildAddressURL(this.event.location);
293294
}
294295

295296
// Check if event was deleted in offine.

src/addons/calendar/services/calendar.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
1616
import { CoreSites } from '@services/sites';
1717
import { CoreSite } from '@classes/sites/site';
1818
import { CoreNetwork } from '@services/network';
19-
import { CoreTextUtils } from '@services/utils/text';
19+
import { CoreText } from '@singletons/text';
2020
import { CoreTimeUtils } from '@services/utils/time';
2121
import { CoreUrl } from '@singletons/url';
2222
import { CoreUtils } from '@services/utils/utils';
@@ -330,7 +330,7 @@ export class AddonCalendarProvider {
330330
): Promise<string> {
331331

332332
const getTimeHtml = (time: string, a11yLangKey: string): string =>
333-
`<span aria-label="${Translate.instant(a11yLangKey, { $a: CoreTextUtils.cleanTags(time) })}">${time}</span>`;
333+
`<span aria-label="${Translate.instant(a11yLangKey, { $a: CoreText.cleanTags(time) })}">${time}</span>`;
334334
const getStartTimeHtml = (time: string): string => getTimeHtml(time, 'core.startingtime');
335335
const getEndTimeHtml = (time: string): string => getTimeHtml(time, 'core.endingtime');
336336

@@ -666,18 +666,18 @@ export class AddonCalendarProvider {
666666
eventConverted.iscategoryevent = originalEvent.eventtype == AddonCalendarEventType.CATEGORY;
667667
eventConverted.normalisedeventtype = this.getEventType(recordAsRecord);
668668
try {
669-
eventConverted.category = CoreTextUtils.parseJSON(recordAsRecord.category || '');
669+
eventConverted.category = CoreText.parseJSON(recordAsRecord.category || '');
670670
} catch {
671671
// Ignore errors.
672672
}
673673

674674
try {
675-
eventConverted.course = CoreTextUtils.parseJSON(recordAsRecord.course || '');
675+
eventConverted.course = CoreText.parseJSON(recordAsRecord.course || '');
676676
} catch {
677677
// Ignore errors.
678678
}
679679
try {
680-
eventConverted.subscription = CoreTextUtils.parseJSON(recordAsRecord.subscription || '');
680+
eventConverted.subscription = CoreText.parseJSON(recordAsRecord.subscription || '');
681681
} catch {
682682
// Ignore errors.
683683
}

src/addons/filter/displayh5p/services/handlers/displayh5p.ts

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { makeSingleton } from '@singletons';
2020
import { CoreH5PPlayerComponent } from '@features/h5p/components/h5p-player/h5p-player';
2121
import { CoreUrl } from '@singletons/url';
2222
import { CoreH5PHelper } from '@features/h5p/classes/helper';
23+
import { CoreText } from '@singletons/text';
2324

2425
/**
2526
* Handler to support the Display H5P filter.
@@ -30,47 +31,45 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle
3031
name = 'AddonFilterDisplayH5PHandler';
3132
filterName = 'displayh5p';
3233

33-
protected template = document.createElement('template'); // A template element to convert HTML to element.
34-
3534
/**
3635
* @inheritdoc
3736
*/
3837
filter(
3938
text: string,
4039
): string | Promise<string> {
41-
this.template.innerHTML = text;
42-
43-
const h5pIframes = <HTMLIFrameElement[]> Array.from(this.template.content.querySelectorAll('iframe.h5p-iframe'));
44-
45-
// Replace all iframes with an empty div that will be treated in handleHtml.
46-
h5pIframes.forEach((iframe) => {
47-
const placeholder = document.createElement('div');
48-
49-
placeholder.classList.add('core-h5p-tmp-placeholder');
50-
placeholder.setAttribute('data-player-src', iframe.src);
51-
52-
iframe.parentElement?.replaceChild(placeholder, iframe);
40+
return CoreText.processHTML(text, (element) => {
41+
const h5pIframes = <HTMLIFrameElement[]> Array.from(element.querySelectorAll('iframe.h5p-iframe'));
42+
43+
// Replace all iframes with an empty div that will be treated in handleHtml.
44+
h5pIframes.forEach((iframe) => {
45+
const placeholder = document.createElement('div');
46+
47+
placeholder.classList.add('core-h5p-tmp-placeholder');
48+
placeholder.setAttribute('data-player-src', iframe.src);
49+
50+
iframe.parentElement?.replaceChild(placeholder, iframe);
51+
});
52+
53+
// Handle H5P iframes embedded using the embed HTML code.
54+
const embeddedH5PIframes = <HTMLIFrameElement[]> Array.from(
55+
element.querySelectorAll('iframe.h5p-player'),
56+
);
57+
58+
embeddedH5PIframes.forEach((iframe) => {
59+
// Add the preventredirect param to allow authenticating if auto-login fails.
60+
iframe.src = CoreUrl.addParamsToUrl(iframe.src, { preventredirect: false });
61+
62+
// Add resizer script so the H5P has the right height.
63+
CoreH5PHelper.addResizerScript();
64+
65+
// If the iframe has a small height, add some minimum initial height so it's seen if auto-login fails.
66+
const styleHeight = Number(iframe.style.height);
67+
const height = Number(iframe.getAttribute('height'));
68+
if ((!height || height < 400) && (!styleHeight || styleHeight < 400)) {
69+
iframe.style.height = '400px';
70+
}
71+
});
5372
});
54-
55-
// Handle H5P iframes embedded using the embed HTML code.
56-
const embeddedH5PIframes = <HTMLIFrameElement[]> Array.from(this.template.content.querySelectorAll('iframe.h5p-player'));
57-
58-
embeddedH5PIframes.forEach((iframe) => {
59-
// Add the preventredirect param to allow authenticating if auto-login fails.
60-
iframe.src = CoreUrl.addParamsToUrl(iframe.src, { preventredirect: false });
61-
62-
// Add resizer script so the H5P has the right height.
63-
CoreH5PHelper.addResizerScript();
64-
65-
// If the iframe has a small height, add some minimum initial height so it's seen if auto-login fails.
66-
const styleHeight = Number(iframe.style.height);
67-
const height = Number(iframe.getAttribute('height'));
68-
if ((!height || height < 400) && (!styleHeight || styleHeight < 400)) {
69-
iframe.style.height = '400px';
70-
}
71-
});
72-
73-
return this.template.innerHTML;
7473
}
7574

7675
/**

src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { CoreFilterDefaultHandler } from '@features/filter/services/handlers/def
1818
import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter';
1919
import { CoreLang } from '@services/lang';
2020
import { CoreSites } from '@services/sites';
21-
import { CoreTextUtils } from '@services/utils/text';
21+
import { CoreText } from '@singletons/text';
2222
import { CoreUtils } from '@services/utils/utils';
2323
import { CoreEvents } from '@singletons/events';
2424
import { CoreSite } from '@classes/sites/site';
@@ -189,7 +189,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
189189
* @returns The whole text with the span inserted around the defined substring.
190190
*/
191191
protected insertSpan(text: string, start: number, end: number): string {
192-
return CoreTextUtils.substrReplace(
192+
return CoreText.substrReplace(
193193
text,
194194
'<span class="nolink">' + text.substring(start, end + 1) + '</span>',
195195
start,

src/addons/filter/mediaplugin/services/handlers/mediaplugin.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import { CoreText } from '@singletons/text';
1516
import { AddonFilterMediaPluginVideoJS } from '@addons/filter/mediaplugin/services/videojs';
1617
import { Injectable } from '@angular/core';
1718

@@ -28,21 +29,17 @@ export class AddonFilterMediaPluginHandlerService extends CoreFilterDefaultHandl
2829
name = 'AddonFilterMediaPluginHandler';
2930
filterName = 'mediaplugin';
3031

31-
protected template = document.createElement('template'); // A template element to convert HTML to element.
32-
3332
/**
3433
* @inheritdoc
3534
*/
3635
filter(text: string): string | Promise<string> {
37-
this.template.innerHTML = text;
38-
39-
const videos = Array.from(this.template.content.querySelectorAll('video'));
36+
return CoreText.processHTML(text, (element) => {
37+
const videos = Array.from(element.querySelectorAll('video'));
4038

41-
videos.forEach((video) => {
42-
AddonFilterMediaPluginVideoJS.treatYoutubeVideos(video);
39+
videos.forEach((video) => {
40+
AddonFilterMediaPluginVideoJS.treatYoutubeVideos(video);
41+
});
4342
});
44-
45-
return this.template.innerHTML;
4643
}
4744

4845
/**

0 commit comments

Comments
 (0)