Skip to content

Commit

Permalink
Back|Forward|Close
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Oct 13, 2011
1 parent 3788400 commit 1832031
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 22 deletions.
Binary file added framework/Images/appbar.back.rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added framework/Images/appbar.close.rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added framework/Images/appbar.next.rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 56 additions & 6 deletions framework/PhoneGap/Commands/ChildBrowserCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ChildBrowserCommand : BaseCommand
{

private static WebBrowser browser;
private static ApplicationBarIconButton backButton;
private static ApplicationBarIconButton fwdButton;

// Display an inderminate progress indicator
public void showWebPage(string options)
Expand Down Expand Up @@ -59,6 +61,8 @@ public void showWebPage(string options)
browser = new WebBrowser();
browser.Navigate(loc);
browser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(browser_LoadCompleted);
browser.Navigating += new EventHandler<NavigatingEventArgs>(browser_Navigating);
browser.NavigationFailed += new System.Windows.Navigation.NavigationFailedEventHandler(browser_NavigationFailed);
browser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(browser_Navigated);
Expand All @@ -70,32 +74,78 @@ public void showWebPage(string options)
ApplicationBar bar = new ApplicationBar();
bar.BackgroundColor = Colors.Black;
bar.IsMenuEnabled = false;
backButton = new ApplicationBarIconButton();
backButton.Text = "Back";
backButton.IconUri = new Uri("/Images/appbar.back.rest.png", UriKind.Relative);
backButton.Click += new EventHandler(backButton_Click);
backButton.IsEnabled = false;
bar.Buttons.Add(backButton);
fwdButton = new ApplicationBarIconButton();
fwdButton.Text = "Forward";
fwdButton.IconUri = new Uri("/Images/appbar.next.rest.png", UriKind.Relative);
fwdButton.Click += new EventHandler(fwdButton_Click);
fwdButton.IsEnabled = false;
bar.Buttons.Add(fwdButton);
ApplicationBarIconButton closeBtn = new ApplicationBarIconButton();
closeBtn.Text = "Close";
closeBtn.IconUri = new Uri("/Images/appbar_button1.png", UriKind.Relative);
closeBtn.IconUri = new Uri("/Images/appbar.close.rest.png", UriKind.Relative);
closeBtn.Click += new EventHandler(closeBtn_Click);
bar.Buttons.Add(closeBtn);
page.ApplicationBar = bar;
}
}
}
});
}

void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{

}

void fwdButton_Click(object sender, EventArgs e)
{
if (browser != null)
{
try
{
browser.InvokeScript("execScript", "history.forward();");
}
catch(Exception)
{

}
}
}

void backButton_Click(object sender, EventArgs e)
{
if (browser != null)
{
try
{
browser.InvokeScript("execScript", "history.back();");
}
catch (Exception)
{

}
}
});
}
}

void closeBtn_Click(object sender, EventArgs e)
{
this.close("");
this.close();
}


public void close(string options)
public void close(string options="")
{
if (browser != null)
{
Expand Down
9 changes: 9 additions & 0 deletions framework/WP7GapClassLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,18 @@
</Page>
</ItemGroup>
<ItemGroup>
<Content Include="Images\appbar.back.rest.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\appbar.close.rest.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\appbar.feature.video.rest.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Images\appbar.next.rest.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\appbar.stop.rest.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
4 changes: 2 additions & 2 deletions tests/MobileSpecUnitTests/www/ChildBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ ChildBrowser.prototype.showWebPage = function(loc,geolocationEnabled)
{
var success = function(msg)
{
console.log("showWebPage success :: " + msg);
console.log("ChildBrowser.showWebPage success :: " + msg);
};

var error = function(e)
{
console.log("showWebPage error :: " + msg);
console.log("ChildBrowser.showWebPage error :: " + e);
};

var options =
Expand Down
39 changes: 25 additions & 14 deletions tests/MobileSpecUnitTests/www/childBrowser.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<html>
<head>
<!-- meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=2.0, maximum-scale=4.0, minimum-scale=1.0" / -->

<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />

<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

<title>PhoneGap - ChildBrowser</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen"/>

Expand All @@ -29,52 +32,60 @@

<script type="text/javascript" charset="utf-8">

var childBrowser;

function onDeviceReady(e)
{
var cb = ChildBrowser.install();
if(cb != null)
{
cb.onLocationChange = function(loc){locChanged(loc); };
cb.onClose = function(){onCloseBrowser()};
cb.onOpenExternal = function(){onOpenExternal();};
childBrowser = ChildBrowser.install();

}

window.plugins.childBrowser.showWebPage("http://google.com");
function openAppHub()
{
if(childBrowser != null)
{
childBrowser.onLocationChange = function(loc){locChanged(loc); };
childBrowser.onClose = function(){onCloseBrowser()};
childBrowser.onOpenExternal = function(){onOpenExternal();};
childBrowser.showWebPage("http://create.msdn.com");

}
}

function onCloseBrowser()
{
console.log("In index.html child browser closed");
console.log("onCloseBrowser");
}

function locChanged(loc)
{
console.log("In index.html new loc = " + loc);
console.log("locChanged = " + loc);
}

function onOpenExternal()
{
console.log("In index.html onOpenExternal");
console.log("onOpenExternal In index.html onOpenExternal");
}



/**
* Function called when page has finished loading.
*/
function init() {

document.addEventListener("deviceready",onDeviceReady, false);
function init()
{
document.addEventListener("deviceready",onDeviceReady, false);
}

</script>


</head>

<body onLoad="init();" id="stage" class="theme">

<div class="btn large" onclick="openAppHub();">Open AppHub</div>

<a href="index.html" class="backBtn">Back</a>
<a href="index.html" class="backBtn">Back</a>
</body>
</html>

0 comments on commit 1832031

Please sign in to comment.