mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Extracts common logic into web-view-common. The check for http/https is now case insensitive. Fixes #819
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
import view = require("ui/core/view");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import utils = require("utils/utils");
|
||||
import fs = require("file-system");
|
||||
import trace = require("trace");
|
||||
|
||||
var urlProperty = new dependencyObservable.Property(
|
||||
"url",
|
||||
@@ -35,7 +38,26 @@ function onSrcPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
return;
|
||||
}
|
||||
|
||||
webView._loadSrc(data.newValue);
|
||||
webView.stopLoading();
|
||||
|
||||
var src = <string>data.newValue;
|
||||
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)) {
|
||||
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
|
||||
@@ -101,7 +123,19 @@ export class WebView extends view.View implements definition.WebView {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
public _loadSrc(src: string) {
|
||||
public _loadFileOrResource(path: string, content: string) {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
public _loadHttp(src: string) {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
public _loadData(src: string) {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
public stopLoading(): void {
|
||||
throw new Error("This member is abstract.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user