Skip to content

Commit

Permalink
Add more checks on document undefined #7855
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Feb 12, 2024
1 parent dbcae3f commit 236ed97
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ export class QuestionRowModel extends Base {
}
protected _scrollableParent: any = undefined;
protected _updateVisibility: any = undefined;
public startLazyRendering(
rowContainerDiv: HTMLElement,
findScrollableContainer = findScrollableParent
) {
public startLazyRendering(rowContainerDiv: HTMLElement, findScrollableContainer = findScrollableParent): void {
if ("undefined" === typeof document) return;
this._scrollableParent = findScrollableContainer(rowContainerDiv);
// if this._scrollableParent is html the scroll event isn't fired, so we should use window
if (this._scrollableParent === document.documentElement) {
Expand Down
14 changes: 8 additions & 6 deletions src/popup-dropdown-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ export class PopupDropdownViewModel extends PopupBaseViewModel {

protected getActualHorizontalPosition(): "left" | "center" | "right" {
let actualHorizontalPosition = this.model.horizontalPosition;
let isRtl = !!document && document.defaultView.getComputedStyle(document.body).direction == "rtl";
if (isRtl) {
if (this.model.horizontalPosition === "left") {
actualHorizontalPosition = "right";
} else if (this.model.horizontalPosition === "right") {
actualHorizontalPosition = "left";
if ("undefined" !== typeof document) {
let isRtl = !!document && document.defaultView.getComputedStyle(document.body).direction == "rtl";
if (isRtl) {
if (this.model.horizontalPosition === "left") {
actualHorizontalPosition = "right";
} else if (this.model.horizontalPosition === "right") {
actualHorizontalPosition = "left";
}
}
}
return actualHorizontalPosition;
Expand Down
5 changes: 4 additions & 1 deletion src/question_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ export class QuestionBooleanModel extends Question {
return true;
}
private calculateBooleanValueByEvent(event: any, isRightClick: boolean) {
var isRtl = document.defaultView.getComputedStyle(event.target).direction == "rtl";
let isRtl = false;
if ("undefined" !== typeof document) {
isRtl = document.defaultView.getComputedStyle(event.target).direction == "rtl";
}
this.booleanValue = isRtl ? !isRightClick : isRightClick;
}
public onSwitchClickModel(event: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
}
private isContainsSelection(el: any) {
let elementWithSelection: any = undefined;
if ((document as any)["selection"]) {
if ((typeof document !== "undefined") && (document as any)["selection"]) {
elementWithSelection = (document as any)["selection"].createRange().parentElement();
}
else {
Expand Down
3 changes: 2 additions & 1 deletion src/svgbundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class SvgIconRegistry {
public registerIconFromSymbol(iconId: string, iconSymbolSvg: string) {
this.icons[iconId] = iconSymbolSvg;
}
public registerIconFromSvgViaElement(iconId: string, iconSvg: string, iconPrefix: string = this.iconPrefix) {
public registerIconFromSvgViaElement(iconId: string, iconSvg: string, iconPrefix: string = this.iconPrefix): void {
if(typeof document === "undefined") return;
iconId = this.processId(iconId, iconPrefix);
let divSvg = document.createElement("div");
divSvg.innerHTML = iconSvg;
Expand Down

0 comments on commit 236ed97

Please sign in to comment.