aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/WebBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-02-03 10:35:29 -0500
committerbobzel <zzzman@gmail.com>2021-02-03 10:35:29 -0500
commitdf23545cff9c612a91272c16fa819f8b53c310d0 (patch)
treefc9a1843ece24e9691466c0b4e32bb95d9431a6d /src/client/views/nodes/WebBox.tsx
parent5666aa3b921024c0f7e6ebb48e0e8f50bb770e79 (diff)
fixed webBox forward/backward and in lightbox.
Diffstat (limited to 'src/client/views/nodes/WebBox.tsx')
-rw-r--r--src/client/views/nodes/WebBox.tsx45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx
index 4b7f0bf77..438395ab0 100644
--- a/src/client/views/nodes/WebBox.tsx
+++ b/src/client/views/nodes/WebBox.tsx
@@ -25,7 +25,6 @@ import { ContextMenuProps } from "../ContextMenuItem";
import { ViewBoxAnnotatableComponent } from "../DocComponent";
import { DocumentDecorations } from "../DocumentDecorations";
import { Annotation } from "../pdf/Annotation";
-import { AnchorMenu } from "../pdf/AnchorMenu";
import { FieldView, FieldViewProps } from './FieldView';
import "./WebBox.scss";
import React = require("react");
@@ -57,6 +56,7 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
get _collapsed() { return StrCast(this.layoutDoc._chromeStatus) !== "enabled"; }
set _collapsed(value) { this.layoutDoc._chromeStatus = !value ? "enabled" : "disabled"; }
get webpage() { return this._iframe?.contentDocument?.children[0]; }
+ url = () => this._url;
constructor(props: any) {
super(props);
@@ -76,8 +76,7 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
href = (typeof (ele.href) === "string" ? ele.href : ele.href?.baseVal) || ele.parentElement?.href || href;
}
if (href) {
- this._url = href.replace(Utils.prepend(""), Cast(this.dataDoc[this.fieldKey], WebField, null)?.url.origin);
- this.submitURL();
+ this.submitURL(href.replace(Utils.prepend(""), Cast(this.dataDoc[this.fieldKey], WebField, null)?.url.origin));
}
})));
iframe.contentDocument.addEventListener('wheel', this.iframeWheel, false);
@@ -149,7 +148,13 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
}));
}
}
+
+ getAnchor = () => this.rootDoc;
+
+
async componentDidMount() {
+ this.props.setContentView?.(this); // this tells the DocumentView that this AudioBox is the "content" of the document. this allows the DocumentView to indirectly call getAnchor() on the AudioBox when making a link.
+
const urlField = Cast(this.dataDoc[this.props.fieldKey], WebField);
runInAction(() => this._url = urlField?.url.toString() || "");
@@ -194,21 +199,6 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
this._iframe?.removeEventListener('wheel', this.iframeWheel);
}
- onUrlDragover = (e: React.DragEvent) => { e.preventDefault(); };
-
- @undoBatch
- @action
- onUrlDrop = (e: React.DragEvent) => {
- const { dataTransfer } = e;
- const html = dataTransfer.getData("text/html");
- const uri = dataTransfer.getData("text/uri-list");
- const url = uri || html || this._url;
- this._url = url.startsWith(window.location.origin) ?
- url.replace(window.location.origin, this._url.match(/http[s]?:\/\/[^\/]*/)?.[0] || "") : url;
- this.submitURL();
- e.stopPropagation();
- }
-
@action
forward = () => {
const future = Cast(this.dataDoc[this.fieldKey + "-future"], listSpec("string"), null);
@@ -218,7 +208,9 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)] = new List<Doc>(DocListCast(this.dataDoc[this.annotationKey]));
this.dataDoc[this.fieldKey] = new WebField(new URL(this._url = future.pop()!));
this.dataDoc[this.annotationKey] = new List<Doc>(DocListCast(this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)]));
+ return true;
}
+ return false;
}
@action
@@ -231,7 +223,9 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)] = new List<Doc>(DocListCast(this.dataDoc[this.annotationKey]));
this.dataDoc[this.fieldKey] = new WebField(new URL(this._url = history.pop()!));
this.dataDoc[this.annotationKey] = new List<Doc>(DocListCast(this.dataDoc[this.annotationKey + "-" + this.urlHash(this._url)]));
+ return true;
}
+ return false;
}
urlHash(s: string) {
@@ -239,10 +233,9 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
}
@action
- submitURL = () => {
- if (!this._url.startsWith("http")) this._url = "http://" + this._url;
+ submitURL = (newUrl: string) => {
+ if (!newUrl.startsWith("http")) newUrl = "http://" + newUrl;
try {
- const URLy = new URL(this._url);
const future = Cast(this.dataDoc[this.fieldKey + "-future"], listSpec("string"), null);
const history = Cast(this.dataDoc[this.fieldKey + "-history"], listSpec("string"), null);
const annos = DocListCast(this.dataDoc[this.annotationKey]);
@@ -250,25 +243,21 @@ export class WebBox extends ViewBoxAnnotatableComponent<FieldViewProps, WebDocum
if (url) {
if (history === undefined) {
this.dataDoc[this.fieldKey + "-history"] = new List<string>([url]);
-
} else {
history.push(url);
}
+ this.layoutDoc._scrollTop = 0;
future && (future.length = 0);
this.dataDoc[this.annotationKey + "-" + this.urlHash(url)] = new List<Doc>(annos);
}
- this.dataDoc[this.fieldKey] = new WebField(URLy);
+ this._url = newUrl;
+ this.dataDoc[this.fieldKey] = new WebField(new URL(newUrl));
this.dataDoc[this.annotationKey] = new List<Doc>([]);
} catch (e) {
console.log("WebBox URL error:" + this._url);
}
}
- onValueKeyDown = async (e: React.KeyboardEvent) => {
- if (e.key === "Enter") this.submitURL();
- e.stopPropagation();
- }
-
editToggleBtn() {
return <Tooltip title={<div className="dash-tooltip" >{`${this.props.Document.isAnnotating ? "Exit" : "Enter"} annotation mode`}</div>}>
<div className="webBox-annotationToggle"