You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/09/19 01:53:16 UTC
[05/10] git commit: Update windows proxy to be both compatible with
windows 8 and 8.1
Update windows proxy to be both compatible with windows 8 and 8.1
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/ac9c6496
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/ac9c6496
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/ac9c6496
Branch: refs/heads/master
Commit: ac9c64964e17e66075c8b9170a61916b5ac01acb
Parents: 225bde2
Author: SomaticIT <co...@somatic.fr>
Authored: Fri Jul 11 21:43:37 2014 +0200
Committer: SomaticIT <co...@somatic.fr>
Committed: Fri Jul 11 21:43:37 2014 +0200
----------------------------------------------------------------------
src/windows/InAppBrowserProxy.js | 81 ++++++++++++++++++++++-------------
1 file changed, 52 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/ac9c6496/src/windows/InAppBrowserProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/InAppBrowserProxy.js b/src/windows/InAppBrowserProxy.js
index 860f739..2bcef49 100644
--- a/src/windows/InAppBrowserProxy.js
+++ b/src/windows/InAppBrowserProxy.js
@@ -31,6 +31,16 @@ var browserWrap,
popup,
cb;
+function onResize() {
+ if (browserWrap && popup) {
+ browserWrap.style.width = (window.innerWidth - 80) + "px";
+ browserWrap.style.height = (window.innerHeight - 80) + "px";
+
+ popup.style.width = (window.innerWidth - 80) + "px";
+ popup.style.height = (window.innerHeight - 80) + "px";
+ }
+}
+
var IAB = {
close: function (win, lose) {
if (browserWrap) {
@@ -40,6 +50,8 @@ var IAB = {
browserWrap = null;
popup = null;
cb = null;
+
+ window.removeEventListener("resize", onResize);
}
},
show: function (win, lose) {
@@ -51,6 +63,7 @@ var IAB = {
var strUrl = args[0],
target = args[1],
features = args[2],
+ isWinJS2 = !!WinJS.Utilities.Scheduler && !!WinJS.Utilities.Scheduler.schedule,
url;
if (target === "_system") {
@@ -81,35 +94,45 @@ var IAB = {
browserWrap.style.display = "none";
}
- popup = document.createElement("x-ms-webview");
+ popup = document.createElement(isWinJS2 ? "x-ms-webview" : "iframe");
popup.style.width = (window.innerWidth - 80) + "px";
popup.style.height = (window.innerHeight - 80) + "px";
+ popup.style.borderWidth = "0px";
popup.src = strUrl;
- popup.addEventListener("MSWebViewNavigationStarting", function (e) {
- win({ type: "loadstart", url: e.uri });
- });
- popup.addEventListener("MSWebViewNavigationCompleted", function (e) {
- if (e.isSuccess) {
- win({ type: "loadstop", url: e.uri });
- }
- else {
+ if (isWinJS2) {
+ popup.addEventListener("MSWebViewNavigationStarting", function (e) {
+ win({ type: "loadstart", url: e.uri });
+ });
+ popup.addEventListener("MSWebViewNavigationCompleted", function (e) {
+ if (e.isSuccess) {
+ win({ type: "loadstop", url: e.uri });
+ }
+ else {
+ win({ type: "loaderror", url: e.uri });
+ }
+ });
+ popup.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
win({ type: "loaderror", url: e.uri });
- }
- });
- popup.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
- win({ type: "loaderror", url: e.uri });
- });
+ });
+ }
+ else {
+ var onError = function () {
+ win({ type: "loaderror", url: this.contentWindow.location });
+ };
- window.addEventListener("resize", function () {
- if (browserWrap && popup) {
- browserWrap.style.width = (window.innerWidth - 80) + "px";
- browserWrap.style.height = (window.innerHeight - 80) + "px";
+ popup.addEventListener("unload", function () {
+ win({ type: "loadstart", url: this.contentWindow.location });
+ });
+ popup.addEventListener("load", function () {
+ win({ type: "loadstop", url: this.contentWindow.location });
+ });
- popup.style.width = (window.innerWidth - 80) + "px";
- popup.style.height = (window.innerHeight - 80) + "px";
- }
- });
+ popup.addEventListener("error", onError);
+ popup.addEventListener("abort", onError);
+ }
+
+ window.addEventListener("resize", onResize);
browserWrap.appendChild(popup);
}
@@ -120,21 +143,22 @@ var IAB = {
injectScriptCode: function (win, fail, args) {
var code = args[0],
- hasCallback = args[1];
+ hasCallback = args[1],
+ isWinJS2 = !!WinJS.Utilities.Scheduler && !!WinJS.Utilities.Scheduler.schedule;
- if (browserWrap && popup) {
+ if (isWinJS2 && browserWrap && popup) {
var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function () { hasCallback && win([]); };
op.onerror = function () { };
op.start();
}
- // "(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c); })(document)"
},
injectScriptFile: function (win, fail, args) {
var file = args[0],
- hasCallback = args[1];
+ hasCallback = args[1],
+ isWinJS2 = !!WinJS.Utilities.Scheduler && !!WinJS.Utilities.Scheduler.schedule;
- if (browserWrap && popup) {
+ if (isWinJS2 && browserWrap && popup) {
Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function () { hasCallback && win([]); };
@@ -147,5 +171,4 @@ var IAB = {
module.exports = IAB;
-
-require("cordova/windows8/commandProxy").add("InAppBrowser", module.exports);
+require("cordova/exec/proxy").add("InAppBrowser", module.exports);