Merge pull request #625 from NativeScript/webview-base-url

Webview base url
This commit is contained in:
Vladimir Enchev
2015-08-25 15:58:59 +03:00
7 changed files with 32 additions and 5 deletions

View File

@ -150,6 +150,8 @@
<TypeScriptCompile Include="apps\tests\ui\repeaterItems-bindingToGestures.ts" /> <TypeScriptCompile Include="apps\tests\ui\repeaterItems-bindingToGestures.ts" />
<TypeScriptCompile Include="apps\tests\xml-declaration\inherited-base-page.ts" /> <TypeScriptCompile Include="apps\tests\xml-declaration\inherited-base-page.ts" />
<TypeScriptCompile Include="apps\tests\xml-declaration\inherited-page.ts" /> <TypeScriptCompile Include="apps\tests\xml-declaration\inherited-page.ts" />
<Content Include="apps\tests\xml-declaration\test.css" />
<Content Include="apps\tests\xml-declaration\test.html" />
<Content Include="apps\ui-tests-app\app.css" /> <Content Include="apps\ui-tests-app\app.css" />
<TypeScriptCompile Include="apps\ui-tests-app\pages\handlers.ts" /> <TypeScriptCompile Include="apps\ui-tests-app\pages\handlers.ts" />
<TypeScriptCompile Include="apps\ui-tests-app\pages\htmlview.ts" /> <TypeScriptCompile Include="apps\ui-tests-app\pages\htmlview.ts" />
@ -965,7 +967,10 @@
<Content Include="apps\ui-tests-app\pages\text\text-view.xml" /> <Content Include="apps\ui-tests-app\pages\text\text-view.xml" />
<Content Include="apps\ui-tests-app\pages\text\label.xml" /> <Content Include="apps\ui-tests-app\pages\text\label.xml" />
<Content Include="apps\ui-tests-app\pages\text\button.xml" /> <Content Include="apps\ui-tests-app\pages\text\button.xml" />
<Content Include="apps\ui-tests-app\web-view\test.css" />
<Content Include="apps\ui-tests-app\web-view\test.html" />
<Content Include="apps\ui-tests-app\web-view\webview.xml" /> <Content Include="apps\ui-tests-app\web-view\webview.xml" />
<Content Include="apps\ui-tests-app\web-view\webviewlocalfile.xml" />
<Content Include="fetch\fetch.js" /> <Content Include="fetch\fetch.js" />
<Content Include="css-value\reworkcss-value.js" /> <Content Include="css-value\reworkcss-value.js" />
<Content Include="ui\layouts\stack-layout\package.json"> <Content Include="ui\layouts\stack-layout\package.json">
@ -1944,7 +1949,7 @@
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties> </WebProjectProperties>
</FlavorProperties> </FlavorProperties>
<UserProperties ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2linear-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" /> <UserProperties ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2linear-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" />
</VisualStudio> </VisualStudio>
</ProjectExtensions> </ProjectExtensions>
</Project> </Project>

View File

@ -0,0 +1,3 @@
body {
background-color: green;
}

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>MyTitle</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="test.css">
</head>
<body>
<span style="color:red">Test</span>
</body>
</html>

View File

@ -2,7 +2,7 @@
<ListView loaded="loaded"> <ListView loaded="loaded">
<ListView.itemTemplate> <ListView.itemTemplate>
<WebView loaded="onLoaded" loadStarted="onLoadStarted" loadFinished="onLoadFinished" unloaded="onUnloaded" <WebView loaded="onLoaded" loadStarted="onLoadStarted" loadFinished="onLoadFinished" unloaded="onUnloaded"
url="http://www.bbc.com/" minHeight="250" /> src="http://www.bbc.com/" minHeight="250" />
</ListView.itemTemplate> </ListView.itemTemplate>
</ListView> </ListView>
</Page> </Page>

View File

@ -0,0 +1,6 @@
<Page>
<GridLayout>
<WebView src="~/web-view/test.html" />
</GridLayout>
</Page>

View File

@ -89,8 +89,9 @@ export class WebView extends common.WebView {
var file = fs.File.fromPath(src); var file = fs.File.fromPath(src);
if (file) { if (file) {
file.readText().then((r) => { var baseUrl = `file:///${src.substring(0, src.lastIndexOf('/') + 1)}`;
this._android.loadData(r, "text/html", null); file.readText().then(r => {
this._android.loadDataWithBaseURL(baseUrl, r, "text/html", null, null);
}); });
} }
} else if (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) { } else if (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) {

View File

@ -97,8 +97,9 @@ export class WebView extends common.WebView {
var file = fs.File.fromPath(src); var file = fs.File.fromPath(src);
if (file) { if (file) {
var baseURL = NSURL.fileURLWithPath(NSString.stringWithString(src).stringByDeletingLastPathComponent);
file.readText().then((r) => { file.readText().then((r) => {
this._ios.loadHTMLStringBaseURL(r, null); this._ios.loadHTMLStringBaseURL(r, baseURL);
}); });
} }
} else if (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) { } else if (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) {