mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: format
This commit is contained in:
@@ -10,82 +10,84 @@ export const srcProperty = new Property<WebViewBase, string>({ name: "src" });
|
||||
|
||||
@CSSType("WebView")
|
||||
export abstract class WebViewBase extends ContainerView {
|
||||
public static loadStartedEvent = "loadStarted";
|
||||
public static loadFinishedEvent = "loadFinished";
|
||||
public static loadStartedEvent = "loadStarted";
|
||||
public static loadFinishedEvent = "loadFinished";
|
||||
|
||||
public src: string;
|
||||
public src: string;
|
||||
|
||||
public _onLoadFinished(url: string, error?: string) {
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadFinishedEvent,
|
||||
object: this,
|
||||
url: url,
|
||||
navigationType: undefined,
|
||||
error: error
|
||||
};
|
||||
public _onLoadFinished(url: string, error?: string) {
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadFinishedEvent,
|
||||
object: this,
|
||||
url: url,
|
||||
navigationType: undefined,
|
||||
error: error,
|
||||
};
|
||||
|
||||
this.notify(<any>args);
|
||||
}
|
||||
this.notify(<any>args);
|
||||
}
|
||||
|
||||
public _onLoadStarted(url: string, navigationType: NavigationType) {
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadStartedEvent,
|
||||
object: this,
|
||||
url: url,
|
||||
navigationType: navigationType,
|
||||
error: undefined
|
||||
};
|
||||
public _onLoadStarted(url: string, navigationType: NavigationType) {
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadStartedEvent,
|
||||
object: this,
|
||||
url: url,
|
||||
navigationType: navigationType,
|
||||
error: undefined,
|
||||
};
|
||||
|
||||
this.notify(<any>args);
|
||||
}
|
||||
this.notify(<any>args);
|
||||
}
|
||||
|
||||
abstract _loadUrl(src: string): void;
|
||||
abstract _loadUrl(src: string): void;
|
||||
|
||||
abstract _loadData(src: string): void;
|
||||
abstract _loadData(src: string): void;
|
||||
|
||||
abstract stopLoading(): void;
|
||||
abstract stopLoading(): void;
|
||||
|
||||
get canGoBack(): boolean {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
get canGoBack(): boolean {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
get canGoForward(): boolean {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
get canGoForward(): boolean {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
abstract goBack(): void;
|
||||
abstract goBack(): void;
|
||||
|
||||
abstract goForward(): void;
|
||||
abstract goForward(): void;
|
||||
|
||||
abstract reload(): void;
|
||||
abstract reload(): void;
|
||||
|
||||
[srcProperty.getDefault](): string {
|
||||
return "";
|
||||
}
|
||||
[srcProperty.setNative](src: string) {
|
||||
this.stopLoading();
|
||||
[srcProperty.getDefault](): string {
|
||||
return "";
|
||||
}
|
||||
[srcProperty.setNative](src: string) {
|
||||
this.stopLoading();
|
||||
|
||||
// Add file:/// prefix for local files.
|
||||
// They should be loaded with _loadUrl() method as it handles query params.
|
||||
if (src.indexOf("~/") === 0) {
|
||||
src = `file:///${knownFolders.currentApp().path}/` + src.substr(2);
|
||||
} else if (src.indexOf("/") === 0) {
|
||||
src = "file://" + src;
|
||||
}
|
||||
// Add file:/// prefix for local files.
|
||||
// They should be loaded with _loadUrl() method as it handles query params.
|
||||
if (src.indexOf("~/") === 0) {
|
||||
src = `file:///${knownFolders.currentApp().path}/` + src.substr(2);
|
||||
} else if (src.indexOf("/") === 0) {
|
||||
src = "file://" + src;
|
||||
}
|
||||
|
||||
// loading local files from paths with spaces may fail
|
||||
if (src.toLowerCase().indexOf("file:///") === 0) {
|
||||
src = encodeURI(src);
|
||||
}
|
||||
// loading local files from paths with spaces may fail
|
||||
if (src.toLowerCase().indexOf("file:///") === 0) {
|
||||
src = encodeURI(src);
|
||||
}
|
||||
|
||||
if (src.toLowerCase().indexOf("http://") === 0 ||
|
||||
src.toLowerCase().indexOf("https://") === 0 ||
|
||||
src.toLowerCase().indexOf("file:///") === 0) {
|
||||
this._loadUrl(src);
|
||||
} else {
|
||||
this._loadData(src);
|
||||
}
|
||||
}
|
||||
if (
|
||||
src.toLowerCase().indexOf("http://") === 0 ||
|
||||
src.toLowerCase().indexOf("https://") === 0 ||
|
||||
src.toLowerCase().indexOf("file:///") === 0
|
||||
) {
|
||||
this._loadUrl(src);
|
||||
} else {
|
||||
this._loadData(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: Use an interface with the same name, so that the class above fulfills the 'implements' requirement
|
||||
@@ -93,9 +95,21 @@ export abstract class WebViewBase extends ContainerView {
|
||||
// HACK: We declare all these 'on' statements, so that they can appear in the API reference
|
||||
// HACK: Do we need this? Is it useful? There are static fields to the WebViewBase class for the event names.
|
||||
export interface WebViewBase {
|
||||
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
|
||||
on(event: "loadFinished", callback: (args: LoadEventData) => void, thisArg?: any): void;
|
||||
on(event: "loadStarted", callback: (args: LoadEventData) => void, thisArg?: any): void;
|
||||
on(
|
||||
eventNames: string,
|
||||
callback: (data: EventData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "loadFinished",
|
||||
callback: (args: LoadEventData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "loadStarted",
|
||||
callback: (args: LoadEventData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
}
|
||||
|
||||
srcProperty.register(WebViewBase);
|
||||
|
||||
Reference in New Issue
Block a user