mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
More files migrated.
This commit is contained in:
@@ -1,80 +1,15 @@
|
||||
import definition = require("ui/web-view");
|
||||
import view = require("ui/core/view");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import { WebView as WebViewDefinition, LoadEventData } from "ui/web-view";
|
||||
import { View } from "ui/core/view";
|
||||
import { Property } from "ui/core/properties";
|
||||
import { EventData } from "data/observable";
|
||||
import * as utils from "utils/utils";
|
||||
import * as trace from "trace";
|
||||
import * as fileSystemModule from "file-system";
|
||||
import * as fs from "file-system";
|
||||
|
||||
var fs: typeof fileSystemModule;
|
||||
function ensureFS() {
|
||||
if (!fs) {
|
||||
fs = require("file-system");
|
||||
}
|
||||
}
|
||||
export let srcProperty = new Property<WebViewBase, string>({ name: "url" });
|
||||
srcProperty.register(WebViewBase);
|
||||
|
||||
var urlProperty = new dependencyObservable.Property(
|
||||
"url",
|
||||
"WebView",
|
||||
new proxy.PropertyMetadata("")
|
||||
);
|
||||
|
||||
function onUrlPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var webView = <WebView>data.object;
|
||||
|
||||
if (webView._suspendLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
webView._loadUrl(data.newValue);
|
||||
}
|
||||
|
||||
// register the setNativeValue callback
|
||||
(<proxy.PropertyMetadata>urlProperty.metadata).onSetNativeValue = onUrlPropertyChanged;
|
||||
|
||||
var srcProperty = new dependencyObservable.Property(
|
||||
"src",
|
||||
"WebView",
|
||||
new proxy.PropertyMetadata("")
|
||||
);
|
||||
|
||||
function onSrcPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var webView = <WebView>data.object;
|
||||
|
||||
if (webView._suspendLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
webView.stopLoading();
|
||||
|
||||
var src = <string>data.newValue;
|
||||
if (trace.enabled) {
|
||||
trace.write("WebView._loadSrc(" + src + ")", trace.categories.Debug);
|
||||
}
|
||||
|
||||
if (utils.isFileOrResourcePath(src)) {
|
||||
ensureFS();
|
||||
|
||||
if (src.indexOf("~/") === 0) {
|
||||
src = fs.path.join(fs.knownFolders.currentApp().path, src.replace("~/", ""));
|
||||
}
|
||||
|
||||
if (fs.File.exists(src)) {
|
||||
var file = fs.File.fromPath(src);
|
||||
var content = file.readTextSync();
|
||||
webView._loadFileOrResource(src, content);
|
||||
}
|
||||
} else if (src.toLowerCase().indexOf("http://") === 0 || src.toLowerCase().indexOf("https://") === 0) {
|
||||
webView._loadHttp(src);
|
||||
} else {
|
||||
webView._loadData(src);
|
||||
}
|
||||
}
|
||||
|
||||
// register the setNativeValue callback
|
||||
(<proxy.PropertyMetadata>srcProperty.metadata).onSetNativeValue = onSrcPropertyChanged;
|
||||
|
||||
export abstract class WebView extends view.View implements definition.WebView {
|
||||
export abstract class WebViewBase extends View implements WebViewDefinition {
|
||||
public static loadStartedEvent = "loadStarted";
|
||||
public static loadFinishedEvent = "loadFinished";
|
||||
|
||||
@@ -87,35 +22,17 @@ export abstract class WebView extends view.View implements definition.WebView {
|
||||
"other"
|
||||
];
|
||||
|
||||
public static urlProperty = urlProperty;
|
||||
public static srcProperty = srcProperty;
|
||||
|
||||
public _suspendLoading: boolean;
|
||||
|
||||
get url(): string {
|
||||
return this._getValue(WebView.urlProperty);
|
||||
}
|
||||
|
||||
set url(value: string) {
|
||||
this._setValue(WebView.urlProperty, value);
|
||||
}
|
||||
|
||||
get src(): string {
|
||||
return this._getValue(WebView.srcProperty);
|
||||
}
|
||||
|
||||
set src(value: string) {
|
||||
this._setValue(WebView.srcProperty, value);
|
||||
}
|
||||
public src: string;
|
||||
|
||||
public _onLoadFinished(url: string, error?: string) {
|
||||
|
||||
this._suspendLoading = true;
|
||||
this.url = url;
|
||||
this._suspendLoading = false;
|
||||
|
||||
var args = <definition.LoadEventData>{
|
||||
eventName: WebView.loadFinishedEvent,
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadFinishedEvent,
|
||||
object: this,
|
||||
url: url,
|
||||
navigationType: undefined,
|
||||
@@ -126,8 +43,8 @@ export abstract class WebView extends view.View implements definition.WebView {
|
||||
}
|
||||
|
||||
public _onLoadStarted(url: string, navigationType: string) {
|
||||
var args = <definition.LoadEventData>{
|
||||
eventName: WebView.loadStartedEvent,
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadStartedEvent,
|
||||
object: this,
|
||||
url: url,
|
||||
navigationType: navigationType,
|
||||
@@ -160,4 +77,35 @@ export abstract class WebView extends view.View implements definition.WebView {
|
||||
abstract goForward(): void;
|
||||
|
||||
abstract reload(): void;
|
||||
}
|
||||
|
||||
get [srcProperty.native](): string {
|
||||
return "";
|
||||
}
|
||||
set [srcProperty.native](src: string) {
|
||||
if (this._suspendLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.stopLoading();
|
||||
|
||||
if (trace.enabled) {
|
||||
trace.write("WebView._loadSrc(" + src + ")", trace.categories.Debug);
|
||||
}
|
||||
|
||||
if (utils.isFileOrResourcePath(src)) {
|
||||
if (src.indexOf("~/") === 0) {
|
||||
src = fs.path.join(fs.knownFolders.currentApp().path, src.replace("~/", ""));
|
||||
}
|
||||
|
||||
if (fs.File.exists(src)) {
|
||||
let file = fs.File.fromPath(src);
|
||||
let content = file.readTextSync();
|
||||
this._loadFileOrResource(src, content);
|
||||
}
|
||||
} else if (src.toLowerCase().indexOf("http://") === 0 || src.toLowerCase().indexOf("https://") === 0) {
|
||||
this._loadHttp(src);
|
||||
} else {
|
||||
this._loadData(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user