mirror of
https://github.com/shuto-cn/cordova-plugin-inappbrowser.git
synced 2025-04-22 16:26:23 +08:00
CB-12895 : added eslint and removed jshint
This commit is contained in:
parent
7611645469
commit
902427525f
10
.eslintrc.yml
Normal file
10
.eslintrc.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
root: true
|
||||||
|
extends: semistandard
|
||||||
|
rules:
|
||||||
|
indent:
|
||||||
|
- error
|
||||||
|
- 4
|
||||||
|
camelcase: off
|
||||||
|
padded-blocks: off
|
||||||
|
operator-linebreak: off
|
||||||
|
no-throw-literal: off
|
16
.jshintrc
16
.jshintrc
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"browser": true
|
|
||||||
, "devel": true
|
|
||||||
, "bitwise": true
|
|
||||||
, "undef": true
|
|
||||||
, "trailing": true
|
|
||||||
, "quotmark": false
|
|
||||||
, "indent": 4
|
|
||||||
, "unused": "vars"
|
|
||||||
, "latedef": "nofunc"
|
|
||||||
, "globals": {
|
|
||||||
"module": false,
|
|
||||||
"exports": false,
|
|
||||||
"require": false
|
|
||||||
}
|
|
||||||
}
|
|
12
package.json
12
package.json
@ -44,8 +44,8 @@
|
|||||||
"cordova-firefoxos"
|
"cordova-firefoxos"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run jshint",
|
"test": "npm run eslint",
|
||||||
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
|
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"cordovaDependencies": {
|
"cordovaDependencies": {
|
||||||
@ -60,6 +60,12 @@
|
|||||||
"author": "Apache Software Foundation",
|
"author": "Apache Software Foundation",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jshint": "^2.6.0"
|
"eslint": "^4.0.0",
|
||||||
|
"eslint-config-semistandard": "^11.0.0",
|
||||||
|
"eslint-config-standard": "^10.2.1",
|
||||||
|
"eslint-plugin-import": "^2.3.0",
|
||||||
|
"eslint-plugin-node": "^5.0.0",
|
||||||
|
"eslint-plugin-promise": "^3.5.0",
|
||||||
|
"eslint-plugin-standard": "^3.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,40 +32,40 @@ var browserWrap,
|
|||||||
function attachNavigationEvents (element, callback) {
|
function attachNavigationEvents (element, callback) {
|
||||||
var onError = function () {
|
var onError = function () {
|
||||||
try {
|
try {
|
||||||
callback({ type: "loaderror", url: this.contentWindow.location.href}, {keepCallback: true});
|
callback({ type: 'loaderror', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// blocked by CORS :\
|
// blocked by CORS :\
|
||||||
callback({ type: "loaderror", url: null}, {keepCallback: true});
|
callback({ type: 'loaderror', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
element.addEventListener("pageshow", function () {
|
element.addEventListener('pageshow', function () {
|
||||||
try {
|
try {
|
||||||
callback({ type: "loadstart", url: this.contentWindow.location.href}, {keepCallback: true});
|
callback({ type: 'loadstart', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// blocked by CORS :\
|
// blocked by CORS :\
|
||||||
callback({ type: "loadstart", url: null}, {keepCallback: true});
|
callback({ type: 'loadstart', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("load", function () {
|
element.addEventListener('load', function () {
|
||||||
try {
|
try {
|
||||||
callback({ type: "loadstop", url: this.contentWindow.location.href}, {keepCallback: true});
|
callback({ type: 'loadstop', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// blocked by CORS :\
|
// blocked by CORS :\
|
||||||
callback({ type: "loadstop", url: null}, {keepCallback: true});
|
callback({ type: 'loadstop', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("error", onError);
|
element.addEventListener('error', onError);
|
||||||
element.addEventListener("abort", onError);
|
element.addEventListener('abort', onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
var IAB = {
|
var IAB = {
|
||||||
close: function (win, lose) {
|
close: function (win, lose) {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
// use the "open" function callback so that the exit event is fired properly
|
// use the "open" function callback so that the exit event is fired properly
|
||||||
if (IAB._win) IAB._win({ type: "exit" });
|
if (IAB._win) IAB._win({ type: 'exit' });
|
||||||
|
|
||||||
browserWrap.parentNode.removeChild(browserWrap);
|
browserWrap.parentNode.removeChild(browserWrap);
|
||||||
browserWrap = null;
|
browserWrap = null;
|
||||||
@ -75,34 +75,34 @@ var IAB = {
|
|||||||
|
|
||||||
show: function (win, lose) {
|
show: function (win, lose) {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
browserWrap.style.display = "block";
|
browserWrap.style.display = 'block';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0];
|
||||||
target = args[1],
|
var target = args[1];
|
||||||
features = args[2];
|
var features = args[2];
|
||||||
|
|
||||||
IAB._win = win;
|
IAB._win = win;
|
||||||
|
|
||||||
if (target === "_self" || !target) {
|
if (target === '_self' || !target) {
|
||||||
window.location = strUrl;
|
window.location = strUrl;
|
||||||
} else if (target === "_system") {
|
} else if (target === '_system') {
|
||||||
modulemapper.getOriginalSymbol(window, 'window.open').call(window, strUrl, "_blank");
|
modulemapper.getOriginalSymbol(window, 'window.open').call(window, strUrl, '_blank');
|
||||||
} else {
|
} else {
|
||||||
// "_blank" or anything else
|
// "_blank" or anything else
|
||||||
if (!browserWrap) {
|
if (!browserWrap) {
|
||||||
browserWrap = document.createElement("div");
|
browserWrap = document.createElement('div');
|
||||||
browserWrap.style.position = "absolute";
|
browserWrap.style.position = 'absolute';
|
||||||
browserWrap.style.top = "0";
|
browserWrap.style.top = '0';
|
||||||
browserWrap.style.left = "0";
|
browserWrap.style.left = '0';
|
||||||
browserWrap.style.boxSizing = "border-box";
|
browserWrap.style.boxSizing = 'border-box';
|
||||||
browserWrap.style.borderWidth = "40px";
|
browserWrap.style.borderWidth = '40px';
|
||||||
browserWrap.style.width = "100vw";
|
browserWrap.style.width = '100vw';
|
||||||
browserWrap.style.height = "100vh";
|
browserWrap.style.height = '100vh';
|
||||||
browserWrap.style.borderStyle = "solid";
|
browserWrap.style.borderStyle = 'solid';
|
||||||
browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
|
browserWrap.style.borderColor = 'rgba(0,0,0,0.25)';
|
||||||
|
|
||||||
browserWrap.onclick = function () {
|
browserWrap.onclick = function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -113,71 +113,68 @@ var IAB = {
|
|||||||
document.body.appendChild(browserWrap);
|
document.body.appendChild(browserWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (features.indexOf("hidden=yes") !== -1) {
|
if (features.indexOf('hidden=yes') !== -1) {
|
||||||
browserWrap.style.display = "none";
|
browserWrap.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
popup = document.createElement("iframe");
|
popup = document.createElement('iframe');
|
||||||
popup.style.borderWidth = "0px";
|
popup.style.borderWidth = '0px';
|
||||||
popup.style.width = "100%";
|
popup.style.width = '100%';
|
||||||
|
|
||||||
browserWrap.appendChild(popup);
|
browserWrap.appendChild(popup);
|
||||||
|
|
||||||
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
|
if (features.indexOf('location=yes') !== -1 || features.indexOf('location') === -1) {
|
||||||
popup.style.height = "calc(100% - 60px)";
|
popup.style.height = 'calc(100% - 60px)';
|
||||||
popup.style.marginBottom = "-4px";
|
popup.style.marginBottom = '-4px';
|
||||||
|
|
||||||
navigationButtonsDiv = document.createElement("div");
|
navigationButtonsDiv = document.createElement('div');
|
||||||
navigationButtonsDiv.style.height = "60px";
|
navigationButtonsDiv.style.height = '60px';
|
||||||
navigationButtonsDiv.style.backgroundColor = "#404040";
|
navigationButtonsDiv.style.backgroundColor = '#404040';
|
||||||
navigationButtonsDiv.style.zIndex = "999";
|
navigationButtonsDiv.style.zIndex = '999';
|
||||||
navigationButtonsDiv.onclick = function (e) {
|
navigationButtonsDiv.onclick = function (e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
navigationButtonsDivInner = document.createElement("div");
|
navigationButtonsDivInner = document.createElement('div');
|
||||||
navigationButtonsDivInner.style.paddingTop = "10px";
|
navigationButtonsDivInner.style.paddingTop = '10px';
|
||||||
navigationButtonsDivInner.style.height = "50px";
|
navigationButtonsDivInner.style.height = '50px';
|
||||||
navigationButtonsDivInner.style.width = "160px";
|
navigationButtonsDivInner.style.width = '160px';
|
||||||
navigationButtonsDivInner.style.margin = "0 auto";
|
navigationButtonsDivInner.style.margin = '0 auto';
|
||||||
navigationButtonsDivInner.style.backgroundColor = "#404040";
|
navigationButtonsDivInner.style.backgroundColor = '#404040';
|
||||||
navigationButtonsDivInner.style.zIndex = "999";
|
navigationButtonsDivInner.style.zIndex = '999';
|
||||||
navigationButtonsDivInner.onclick = function (e) {
|
navigationButtonsDivInner.onclick = function (e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
backButton = document.createElement('button');
|
||||||
|
backButton.style.width = '40px';
|
||||||
|
backButton.style.height = '40px';
|
||||||
|
backButton.style.borderRadius = '40px';
|
||||||
|
|
||||||
backButton = document.createElement("button");
|
backButton.innerHTML = '←';
|
||||||
backButton.style.width = "40px";
|
backButton.addEventListener('click', function (e) {
|
||||||
backButton.style.height = "40px";
|
if (popup.canGoBack) { popup.goBack(); }
|
||||||
backButton.style.borderRadius = "40px";
|
|
||||||
|
|
||||||
backButton.innerHTML = "←";
|
|
||||||
backButton.addEventListener("click", function (e) {
|
|
||||||
if (popup.canGoBack)
|
|
||||||
popup.goBack();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
forwardButton = document.createElement("button");
|
forwardButton = document.createElement('button');
|
||||||
forwardButton.style.marginLeft = "20px";
|
forwardButton.style.marginLeft = '20px';
|
||||||
forwardButton.style.width = "40px";
|
forwardButton.style.width = '40px';
|
||||||
forwardButton.style.height = "40px";
|
forwardButton.style.height = '40px';
|
||||||
forwardButton.style.borderRadius = "40px";
|
forwardButton.style.borderRadius = '40px';
|
||||||
|
|
||||||
forwardButton.innerHTML = "→";
|
forwardButton.innerHTML = '→';
|
||||||
forwardButton.addEventListener("click", function (e) {
|
forwardButton.addEventListener('click', function (e) {
|
||||||
if (popup.canGoForward)
|
if (popup.canGoForward) { popup.goForward(); }
|
||||||
popup.goForward();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
closeButton = document.createElement("button");
|
closeButton = document.createElement('button');
|
||||||
closeButton.style.marginLeft = "20px";
|
closeButton.style.marginLeft = '20px';
|
||||||
closeButton.style.width = "40px";
|
closeButton.style.width = '40px';
|
||||||
closeButton.style.height = "40px";
|
closeButton.style.height = '40px';
|
||||||
closeButton.style.borderRadius = "40px";
|
closeButton.style.borderRadius = '40px';
|
||||||
|
|
||||||
closeButton.innerHTML = "✖";
|
closeButton.innerHTML = '✖';
|
||||||
closeButton.addEventListener("click", function (e) {
|
closeButton.addEventListener('click', function (e) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
IAB.close();
|
IAB.close();
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -194,7 +191,7 @@ var IAB = {
|
|||||||
|
|
||||||
browserWrap.appendChild(navigationButtonsDiv);
|
browserWrap.appendChild(navigationButtonsDiv);
|
||||||
} else {
|
} else {
|
||||||
popup.style.height = "100%";
|
popup.style.height = '100%';
|
||||||
}
|
}
|
||||||
|
|
||||||
// start listening for navigation events
|
// start listening for navigation events
|
||||||
@ -205,8 +202,8 @@ var IAB = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
injectScriptCode: function (win, fail, args) {
|
injectScriptCode: function (win, fail, args) {
|
||||||
var code = args[0],
|
var code = args[0];
|
||||||
hasCallback = args[1];
|
var hasCallback = args[1];
|
||||||
|
|
||||||
if (browserWrap && popup) {
|
if (browserWrap && popup) {
|
||||||
try {
|
try {
|
||||||
@ -247,4 +244,4 @@ var IAB = {
|
|||||||
|
|
||||||
module.exports = IAB;
|
module.exports = IAB;
|
||||||
|
|
||||||
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
|
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|
||||||
|
@ -32,7 +32,7 @@ var IABExecs = {
|
|||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
browserWrap.parentNode.removeChild(browserWrap);
|
browserWrap.parentNode.removeChild(browserWrap);
|
||||||
browserWrap = null;
|
browserWrap = null;
|
||||||
if (typeof(win) == "function") win({type:'exit'});
|
if (typeof (win) === 'function') win({type: 'exit'});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -48,17 +48,17 @@ var IABExecs = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0];
|
||||||
target = args[1],
|
var target = args[1];
|
||||||
features_string = args[2] || "location=yes", //location=yes is default
|
var features_string = args[2] || 'location=yes'; // location=yes is default
|
||||||
features = {};
|
var features = {};
|
||||||
|
|
||||||
var features_list = features_string.split(',');
|
var features_list = features_string.split(',');
|
||||||
features_list.forEach(function (feature) {
|
features_list.forEach(function (feature) {
|
||||||
var tup = feature.split('=');
|
var tup = feature.split('=');
|
||||||
if (tup[1] == 'yes') {
|
if (tup[1] === 'yes') {
|
||||||
tup[1] = true;
|
tup[1] = true;
|
||||||
} else if (tup[1] == 'no') {
|
} else if (tup[1] === 'no') {
|
||||||
tup[1] = false;
|
tup[1] = false;
|
||||||
} else {
|
} else {
|
||||||
var number = parseInt(tup[1]);
|
var number = parseInt(tup[1]);
|
||||||
@ -68,7 +68,6 @@ var IABExecs = {
|
|||||||
}
|
}
|
||||||
features[tup[0]] = tup[1];
|
features[tup[0]] = tup[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateIframeSizeNoLocation () {
|
function updateIframeSizeNoLocation () {
|
||||||
browserWrap.style.width = window.innerWidth + 'px';
|
browserWrap.style.width = window.innerWidth + 'px';
|
||||||
browserWrap.style.height = window.innerHeight + 'px';
|
browserWrap.style.height = window.innerHeight + 'px';
|
||||||
|
@ -19,14 +19,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint -W061 */
|
|
||||||
/* global oxide */
|
/* global oxide */
|
||||||
|
|
||||||
oxide.addMessageHandler("EXECUTE", function(msg) {
|
oxide.addMessageHandler('EXECUTE', function (msg) {
|
||||||
var code = msg.args.code;
|
var code = msg.args.code;
|
||||||
try {
|
try {
|
||||||
msg.reply({result: eval(code)});
|
msg.reply({result: eval(code)}); // eslint-disable-line no-eval
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
msg.error("Code threw exception: \"" + e + "\"");
|
msg.error('Code threw exception: "' + e + '"');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
@ -21,9 +21,10 @@
|
|||||||
|
|
||||||
/* jslint sloppy:true */
|
/* jslint sloppy:true */
|
||||||
/* global Windows:true, setImmediate */
|
/* global Windows:true, setImmediate */
|
||||||
|
/* eslint standard/no-callback-literal : 0 */
|
||||||
|
|
||||||
var cordova = require('cordova'),
|
var cordova = require('cordova');
|
||||||
urlutil = require('cordova/urlutil');
|
var urlutil = require('cordova/urlutil');
|
||||||
|
|
||||||
var browserWrap,
|
var browserWrap,
|
||||||
popup,
|
popup,
|
||||||
@ -42,54 +43,54 @@ var isWebViewAvailable = cordova.platformId === 'windows';
|
|||||||
|
|
||||||
function attachNavigationEvents (element, callback) {
|
function attachNavigationEvents (element, callback) {
|
||||||
if (isWebViewAvailable) {
|
if (isWebViewAvailable) {
|
||||||
element.addEventListener("MSWebViewNavigationStarting", function (e) {
|
element.addEventListener('MSWebViewNavigationStarting', function (e) {
|
||||||
callback({ type: "loadstart", url: e.uri}, {keepCallback: true} );
|
callback({ type: 'loadstart', url: e.uri }, {keepCallback: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("MSWebViewNavigationCompleted", function (e) {
|
element.addEventListener('MSWebViewNavigationCompleted', function (e) {
|
||||||
if (e.isSuccess) {
|
if (e.isSuccess) {
|
||||||
callback({ type: "loadstop", url: e.uri }, { keepCallback: true });
|
callback({ type: 'loadstop', url: e.uri }, { keepCallback: true });
|
||||||
} else {
|
} else {
|
||||||
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
|
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
|
element.addEventListener('MSWebViewUnviewableContentIdentified', function (e) {
|
||||||
// WebView found the content to be not HTML.
|
// WebView found the content to be not HTML.
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
|
||||||
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
|
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("MSWebViewContentLoading", function (e) {
|
element.addEventListener('MSWebViewContentLoading', function (e) {
|
||||||
if (navigationButtonsDiv && popup) {
|
if (navigationButtonsDiv && popup) {
|
||||||
if (popup.canGoBack) {
|
if (popup.canGoBack) {
|
||||||
backButton.removeAttribute("disabled");
|
backButton.removeAttribute('disabled');
|
||||||
} else {
|
} else {
|
||||||
backButton.setAttribute("disabled", "true");
|
backButton.setAttribute('disabled', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (popup.canGoForward) {
|
if (popup.canGoForward) {
|
||||||
forwardButton.removeAttribute("disabled");
|
forwardButton.removeAttribute('disabled');
|
||||||
} else {
|
} else {
|
||||||
forwardButton.setAttribute("disabled", "true");
|
forwardButton.setAttribute('disabled', 'true');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var onError = function () {
|
var onError = function () {
|
||||||
callback({ type: "loaderror", url: this.contentWindow.location}, {keepCallback: true});
|
callback({ type: 'loaderror', url: this.contentWindow.location }, {keepCallback: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
element.addEventListener("unload", function () {
|
element.addEventListener('unload', function () {
|
||||||
callback({ type: "loadstart", url: this.contentWindow.location}, {keepCallback: true});
|
callback({ type: 'loadstart', url: this.contentWindow.location }, {keepCallback: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("load", function () {
|
element.addEventListener('load', function () {
|
||||||
callback({ type: "loadstop", url: this.contentWindow.location}, {keepCallback: true});
|
callback({ type: 'loadstop', url: this.contentWindow.location }, {keepCallback: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("error", onError);
|
element.addEventListener('error', onError);
|
||||||
element.addEventListener("abort", onError);
|
element.addEventListener('abort', onError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ var IAB = {
|
|||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
if (navigationEventsCallback) {
|
if (navigationEventsCallback) {
|
||||||
navigationEventsCallback({ type: "exit" });
|
navigationEventsCallback({ type: 'exit' });
|
||||||
}
|
}
|
||||||
|
|
||||||
browserWrap.parentNode.removeChild(browserWrap);
|
browserWrap.parentNode.removeChild(browserWrap);
|
||||||
@ -107,52 +108,52 @@ var IAB = {
|
|||||||
browserWrap = null;
|
browserWrap = null;
|
||||||
popup = null;
|
popup = null;
|
||||||
|
|
||||||
document.removeEventListener("backbutton", hardwareBackCallback, false);
|
document.removeEventListener('backbutton', hardwareBackCallback, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
show: function (win, lose) {
|
show: function (win, lose) {
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
browserWrap.style.display = "block";
|
browserWrap.style.display = 'block';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
hide: function (win, lose) {
|
hide: function (win, lose) {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
browserWrap.style.display = "none";
|
browserWrap.style.display = 'none';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
|
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0];
|
||||||
target = args[1],
|
var target = args[1];
|
||||||
features = args[2],
|
var features = args[2];
|
||||||
url;
|
var url;
|
||||||
|
|
||||||
navigationEventsCallback = win;
|
navigationEventsCallback = win;
|
||||||
|
|
||||||
if (target === "_system") {
|
if (target === '_system') {
|
||||||
url = new Windows.Foundation.Uri(strUrl);
|
url = new Windows.Foundation.Uri(strUrl);
|
||||||
Windows.System.Launcher.launchUriAsync(url);
|
Windows.System.Launcher.launchUriAsync(url);
|
||||||
} else if (target === "_self" || !target) {
|
} else if (target === '_self' || !target) {
|
||||||
window.location = strUrl;
|
window.location = strUrl;
|
||||||
} else {
|
} else {
|
||||||
// "_blank" or anything else
|
// "_blank" or anything else
|
||||||
if (!browserWrap) {
|
if (!browserWrap) {
|
||||||
var browserWrapStyle = document.createElement('link');
|
var browserWrapStyle = document.createElement('link');
|
||||||
browserWrapStyle.rel = "stylesheet";
|
browserWrapStyle.rel = 'stylesheet';
|
||||||
browserWrapStyle.type = "text/css";
|
browserWrapStyle.type = 'text/css';
|
||||||
browserWrapStyle.href = urlutil.makeAbsolute("/www/css/inappbrowser.css");
|
browserWrapStyle.href = urlutil.makeAbsolute('/www/css/inappbrowser.css');
|
||||||
|
|
||||||
document.head.appendChild(browserWrapStyle);
|
document.head.appendChild(browserWrapStyle);
|
||||||
|
|
||||||
browserWrap = document.createElement("div");
|
browserWrap = document.createElement('div');
|
||||||
browserWrap.className = "inAppBrowserWrap";
|
browserWrap.className = 'inAppBrowserWrap';
|
||||||
|
|
||||||
if (features.indexOf("fullscreen=yes") > -1) {
|
if (features.indexOf('fullscreen=yes') > -1) {
|
||||||
browserWrap.classList.add("inAppBrowserWrapFullscreen");
|
browserWrap.classList.add('inAppBrowserWrapFullscreen');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save body overflow style to be able to reset it back later
|
// Save body overflow style to be able to reset it back later
|
||||||
@ -166,22 +167,22 @@ var IAB = {
|
|||||||
|
|
||||||
document.body.appendChild(browserWrap);
|
document.body.appendChild(browserWrap);
|
||||||
// Hide scrollbars for the whole body while inappbrowser's window is open
|
// Hide scrollbars for the whole body while inappbrowser's window is open
|
||||||
document.body.style.msOverflowStyle = "none";
|
document.body.style.msOverflowStyle = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (features.indexOf("hidden=yes") !== -1) {
|
if (features.indexOf('hidden=yes') !== -1) {
|
||||||
browserWrap.style.display = "none";
|
browserWrap.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
popup = document.createElement(isWebViewAvailable ? "x-ms-webview" : "iframe");
|
popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe');
|
||||||
if (popup instanceof HTMLIFrameElement) {
|
if (popup instanceof HTMLIFrameElement) { // eslint-disable-line no-undef
|
||||||
// For iframe we need to override bacground color of parent element here
|
// For iframe we need to override bacground color of parent element here
|
||||||
// otherwise pages without background color set will have transparent background
|
// otherwise pages without background color set will have transparent background
|
||||||
popup.style.backgroundColor = "white";
|
popup.style.backgroundColor = 'white';
|
||||||
}
|
}
|
||||||
popup.style.borderWidth = "0px";
|
popup.style.borderWidth = '0px';
|
||||||
popup.style.width = "100%";
|
popup.style.width = '100%';
|
||||||
popup.style.marginBottom = "-5px";
|
popup.style.marginBottom = '-5px';
|
||||||
|
|
||||||
browserWrap.appendChild(popup);
|
browserWrap.appendChild(popup);
|
||||||
|
|
||||||
@ -191,14 +192,14 @@ var IAB = {
|
|||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (features.indexOf("hardwareback=yes") > -1 || features.indexOf("hardwareback") === -1) {
|
if (features.indexOf('hardwareback=yes') > -1 || features.indexOf('hardwareback') === -1) {
|
||||||
hardwareBackCallback = function () {
|
hardwareBackCallback = function () {
|
||||||
if (browserWrap.style.display === 'none') {
|
if (browserWrap.style.display === 'none') {
|
||||||
// NOTE: backbutton handlers have to throw an exception in order to prevent
|
// NOTE: backbutton handlers have to throw an exception in order to prevent
|
||||||
// returning 'true' inside cordova-js, which would mean that the event is handled by user.
|
// returning 'true' inside cordova-js, which would mean that the event is handled by user.
|
||||||
// Throwing an exception means that the default/system navigation behavior will take place,
|
// Throwing an exception means that the default/system navigation behavior will take place,
|
||||||
// which is to exit the app if the navigation stack is empty.
|
// which is to exit the app if the navigation stack is empty.
|
||||||
throw 'Exit the app';
|
throw 'Exit the app'; // eslint-disable-line no-throw-literal
|
||||||
}
|
}
|
||||||
|
|
||||||
if (popup.canGoBack) {
|
if (popup.canGoBack) {
|
||||||
@ -207,59 +208,57 @@ var IAB = {
|
|||||||
closeHandler();
|
closeHandler();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if (features.indexOf("hardwareback=no") > -1) {
|
} else if (features.indexOf('hardwareback=no') > -1) {
|
||||||
hardwareBackCallback = function () {
|
hardwareBackCallback = function () {
|
||||||
if (browserWrap.style.display === 'none') {
|
if (browserWrap.style.display === 'none') {
|
||||||
// See comment above
|
// See comment above
|
||||||
throw 'Exit the app';
|
throw 'Exit the app'; // eslint-disable-line no-throw-literal
|
||||||
}
|
}
|
||||||
|
|
||||||
closeHandler();
|
closeHandler();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("backbutton", hardwareBackCallback, false);
|
document.addEventListener('backbutton', hardwareBackCallback, false);
|
||||||
|
|
||||||
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
|
if (features.indexOf('location=yes') !== -1 || features.indexOf('location') === -1) {
|
||||||
popup.style.height = "calc(100% - 70px)";
|
popup.style.height = 'calc(100% - 70px)';
|
||||||
|
|
||||||
navigationButtonsDiv = document.createElement("div");
|
navigationButtonsDiv = document.createElement('div');
|
||||||
navigationButtonsDiv.className = "inappbrowser-app-bar";
|
navigationButtonsDiv.className = 'inappbrowser-app-bar';
|
||||||
navigationButtonsDiv.onclick = function (e) {
|
navigationButtonsDiv.onclick = function (e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
navigationButtonsDivInner = document.createElement("div");
|
navigationButtonsDivInner = document.createElement('div');
|
||||||
navigationButtonsDivInner.className = "inappbrowser-app-bar-inner";
|
navigationButtonsDivInner.className = 'inappbrowser-app-bar-inner';
|
||||||
navigationButtonsDivInner.onclick = function (e) {
|
navigationButtonsDivInner.onclick = function (e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
backButton = document.createElement("div");
|
backButton = document.createElement('div');
|
||||||
backButton.innerText = "back";
|
backButton.innerText = 'back';
|
||||||
backButton.className = "app-bar-action action-back";
|
backButton.className = 'app-bar-action action-back';
|
||||||
backButton.addEventListener("click", function (e) {
|
backButton.addEventListener('click', function (e) {
|
||||||
if (popup.canGoBack)
|
if (popup.canGoBack) { popup.goBack(); }
|
||||||
popup.goBack();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
forwardButton = document.createElement("div");
|
forwardButton = document.createElement('div');
|
||||||
forwardButton.innerText = "forward";
|
forwardButton.innerText = 'forward';
|
||||||
forwardButton.className = "app-bar-action action-forward";
|
forwardButton.className = 'app-bar-action action-forward';
|
||||||
forwardButton.addEventListener("click", function (e) {
|
forwardButton.addEventListener('click', function (e) {
|
||||||
if (popup.canGoForward)
|
if (popup.canGoForward) { popup.goForward(); }
|
||||||
popup.goForward();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
closeButton = document.createElement("div");
|
closeButton = document.createElement('div');
|
||||||
closeButton.innerText = "close";
|
closeButton.innerText = 'close';
|
||||||
closeButton.className = "app-bar-action action-close";
|
closeButton.className = 'app-bar-action action-close';
|
||||||
closeButton.addEventListener("click", closeHandler);
|
closeButton.addEventListener('click', closeHandler);
|
||||||
|
|
||||||
if (!isWebViewAvailable) {
|
if (!isWebViewAvailable) {
|
||||||
// iframe navigation is not yet supported
|
// iframe navigation is not yet supported
|
||||||
backButton.setAttribute("disabled", "true");
|
backButton.setAttribute('disabled', 'true');
|
||||||
forwardButton.setAttribute("disabled", "true");
|
forwardButton.setAttribute('disabled', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
navigationButtonsDivInner.appendChild(backButton);
|
navigationButtonsDivInner.appendChild(backButton);
|
||||||
@ -269,14 +268,14 @@ var IAB = {
|
|||||||
|
|
||||||
browserWrap.appendChild(navigationButtonsDiv);
|
browserWrap.appendChild(navigationButtonsDiv);
|
||||||
} else {
|
} else {
|
||||||
popup.style.height = "100%";
|
popup.style.height = '100%';
|
||||||
}
|
}
|
||||||
|
|
||||||
// start listening for navigation events
|
// start listening for navigation events
|
||||||
attachNavigationEvents(popup, navigationEventsCallback);
|
attachNavigationEvents(popup, navigationEventsCallback);
|
||||||
|
|
||||||
if (isWebViewAvailable) {
|
if (isWebViewAvailable) {
|
||||||
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
|
strUrl = strUrl.replace('ms-appx://', 'ms-appx-web://');
|
||||||
}
|
}
|
||||||
popup.src = strUrl;
|
popup.src = strUrl;
|
||||||
}
|
}
|
||||||
@ -285,11 +284,11 @@ var IAB = {
|
|||||||
|
|
||||||
injectScriptCode: function (win, fail, args) {
|
injectScriptCode: function (win, fail, args) {
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
var code = args[0],
|
var code = args[0];
|
||||||
hasCallback = args[1];
|
var hasCallback = args[1];
|
||||||
|
|
||||||
if (isWebViewAvailable && browserWrap && popup) {
|
if (isWebViewAvailable && browserWrap && popup) {
|
||||||
var op = popup.invokeScriptAsync("eval", code);
|
var op = popup.invokeScriptAsync('eval', code);
|
||||||
op.oncomplete = function (e) {
|
op.oncomplete = function (e) {
|
||||||
if (hasCallback) {
|
if (hasCallback) {
|
||||||
// return null if event target is unavailable by some reason
|
// return null if event target is unavailable by some reason
|
||||||
@ -305,10 +304,10 @@ var IAB = {
|
|||||||
|
|
||||||
injectScriptFile: function (win, fail, args) {
|
injectScriptFile: function (win, fail, args) {
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
var filePath = args[0],
|
var filePath = args[0];
|
||||||
hasCallback = args[1];
|
var hasCallback = args[1];
|
||||||
|
|
||||||
if (!!filePath) {
|
if (filePath) {
|
||||||
filePath = urlutil.makeAbsolute(filePath);
|
filePath = urlutil.makeAbsolute(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +316,7 @@ var IAB = {
|
|||||||
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
|
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
|
||||||
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) {
|
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) {
|
||||||
Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
|
Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
|
||||||
var op = popup.invokeScriptAsync("eval", code);
|
var op = popup.invokeScriptAsync('eval', code);
|
||||||
op.oncomplete = function (e) {
|
op.oncomplete = function (e) {
|
||||||
if (hasCallback) {
|
if (hasCallback) {
|
||||||
var result = [e.target.result];
|
var result = [e.target.result];
|
||||||
@ -334,8 +333,8 @@ var IAB = {
|
|||||||
|
|
||||||
injectStyleCode: function (win, fail, args) {
|
injectStyleCode: function (win, fail, args) {
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
var code = args[0],
|
var code = args[0];
|
||||||
hasCallback = args[1];
|
var hasCallback = args[1];
|
||||||
|
|
||||||
if (isWebViewAvailable && browserWrap && popup) {
|
if (isWebViewAvailable && browserWrap && popup) {
|
||||||
injectCSS(popup, code, hasCallback && win);
|
injectCSS(popup, code, hasCallback && win);
|
||||||
@ -345,8 +344,8 @@ var IAB = {
|
|||||||
|
|
||||||
injectStyleFile: function (win, fail, args) {
|
injectStyleFile: function (win, fail, args) {
|
||||||
setImmediate(function () {
|
setImmediate(function () {
|
||||||
var filePath = args[0],
|
var filePath = args[0];
|
||||||
hasCallback = args[1];
|
var hasCallback = args[1];
|
||||||
|
|
||||||
filePath = filePath && urlutil.makeAbsolute(filePath);
|
filePath = filePath && urlutil.makeAbsolute(filePath);
|
||||||
|
|
||||||
@ -368,10 +367,10 @@ var IAB = {
|
|||||||
function injectCSS (webView, cssCode, callback) {
|
function injectCSS (webView, cssCode, callback) {
|
||||||
// This will automatically escape all thing that we need (quotes, slashes, etc.)
|
// This will automatically escape all thing that we need (quotes, slashes, etc.)
|
||||||
var escapedCode = JSON.stringify(cssCode);
|
var escapedCode = JSON.stringify(cssCode);
|
||||||
var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)"
|
var evalWrapper = '(function(d){var c=d.createElement(\'style\');c.innerHTML=%s;d.head.appendChild(c);})(document)'
|
||||||
.replace('%s', escapedCode);
|
.replace('%s', escapedCode);
|
||||||
|
|
||||||
var op = webView.invokeScriptAsync("eval", evalWrapper);
|
var op = webView.invokeScriptAsync('eval', evalWrapper);
|
||||||
op.oncomplete = function () {
|
op.oncomplete = function () {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback([]);
|
callback([]);
|
||||||
@ -383,4 +382,4 @@ function injectCSS (webView, cssCode, callback) {
|
|||||||
|
|
||||||
module.exports = IAB;
|
module.exports = IAB;
|
||||||
|
|
||||||
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
|
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|
||||||
|
2
tests/.eslintrc.yml
Normal file
2
tests/.eslintrc.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
env:
|
||||||
|
jasmine: true
|
@ -16,5 +16,5 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
var d = document.getElementById("header");
|
var d = document.getElementById('header');
|
||||||
d.innerHTML = "Script file successfully injected";
|
d.innerHTML = 'Script file successfully injected';
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint jasmine: true */
|
|
||||||
/* global MSApp */
|
/* global MSApp */
|
||||||
|
|
||||||
var cordova = require('cordova');
|
var cordova = require('cordova');
|
||||||
@ -36,11 +35,11 @@ exports.defineAutoTests = function () {
|
|||||||
|
|
||||||
describe('cordova.InAppBrowser', function () {
|
describe('cordova.InAppBrowser', function () {
|
||||||
|
|
||||||
it("inappbrowser.spec.1 should exist", function () {
|
it('inappbrowser.spec.1 should exist', function () {
|
||||||
expect(cordova.InAppBrowser).toBeDefined();
|
expect(cordova.InAppBrowser).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("inappbrowser.spec.2 should contain open function", function () {
|
it('inappbrowser.spec.2 should contain open function', function () {
|
||||||
expect(cordova.InAppBrowser.open).toBeDefined();
|
expect(cordova.InAppBrowser.open).toBeDefined();
|
||||||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
||||||
});
|
});
|
||||||
@ -48,7 +47,7 @@ exports.defineAutoTests = function () {
|
|||||||
|
|
||||||
describe('open method', function () {
|
describe('open method', function () {
|
||||||
|
|
||||||
if (cordova.platformId == 'osx') {
|
if (cordova.platformId === 'osx') {
|
||||||
pending('Open method not fully supported on OSX.');
|
pending('Open method not fully supported on OSX.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -95,7 +94,7 @@ exports.defineAutoTests = function () {
|
|||||||
expect(evt.message).toEqual(jasmine.any(String));
|
expect(evt.message).toEqual(jasmine.any(String));
|
||||||
}
|
}
|
||||||
|
|
||||||
it("inappbrowser.spec.3 should return InAppBrowser instance with required methods", function () {
|
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
|
||||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||||
|
|
||||||
expect(iabInstance).toBeDefined();
|
expect(iabInstance).toBeDefined();
|
||||||
@ -109,7 +108,7 @@ exports.defineAutoTests = function () {
|
|||||||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("inappbrowser.spec.4 should support loadstart and loadstop events", function (done) {
|
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
|
||||||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
||||||
verifyEvent(evt, 'loadstart');
|
verifyEvent(evt, 'loadstart');
|
||||||
});
|
});
|
||||||
@ -127,7 +126,7 @@ exports.defineAutoTests = function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("inappbrowser.spec.5 should support exit event", function (done) {
|
it('inappbrowser.spec.5 should support exit event', function (done) {
|
||||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||||
iabInstance.addEventListener('exit', function (evt) {
|
iabInstance.addEventListener('exit', function (evt) {
|
||||||
verifyEvent(evt, 'exit');
|
verifyEvent(evt, 'exit');
|
||||||
@ -137,7 +136,7 @@ exports.defineAutoTests = function () {
|
|||||||
iabInstance = null;
|
iabInstance = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("inappbrowser.spec.6 should support loaderror event", function (done) {
|
it('inappbrowser.spec.6 should support loaderror event', function (done) {
|
||||||
if (isBrowser) {
|
if (isBrowser) {
|
||||||
// according to documentation, "loaderror" event is not supported on browser
|
// according to documentation, "loaderror" event is not supported on browser
|
||||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||||
@ -157,7 +156,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
|
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
|
||||||
numExpectedRedirects = numExpectedRedirects || 0;
|
numExpectedRedirects = numExpectedRedirects || 0;
|
||||||
useWindowOpen = useWindowOpen || false;
|
useWindowOpen = useWindowOpen || false;
|
||||||
console.log("Opening " + url);
|
console.log('Opening ' + url);
|
||||||
|
|
||||||
var counts;
|
var counts;
|
||||||
var lastLoadStartURL;
|
var lastLoadStartURL;
|
||||||
@ -183,12 +182,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
if (useWindowOpen) {
|
if (useWindowOpen) {
|
||||||
console.log('Use window.open() for url');
|
console.log('Use window.open() for url');
|
||||||
iab = window.open(url, target, params, callbacks);
|
iab = window.open(url, target, params, callbacks);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
iab = cordova.InAppBrowser.open(url, target, params, callbacks);
|
iab = cordova.InAppBrowser.open(url, target, params, callbacks);
|
||||||
}
|
}
|
||||||
if (!iab) {
|
if (!iab) {
|
||||||
alert('open returned ' + iab);
|
alert('open returned ' + iab); // eslint-disable-line no-undef
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,36 +194,36 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
console.log('IAB event=' + JSON.stringify(e));
|
console.log('IAB event=' + JSON.stringify(e));
|
||||||
counts[e.type]++;
|
counts[e.type]++;
|
||||||
// Verify that event.url gets updated on redirects.
|
// Verify that event.url gets updated on redirects.
|
||||||
if (e.type == 'loadstart') {
|
if (e.type === 'loadstart') {
|
||||||
if (e.url == lastLoadStartURL) {
|
if (e.url === lastLoadStartURL) {
|
||||||
alert('Unexpected: loadstart fired multiple times for the same URL.');
|
alert('Unexpected: loadstart fired multiple times for the same URL.'); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
lastLoadStartURL = e.url;
|
lastLoadStartURL = e.url;
|
||||||
}
|
}
|
||||||
// Verify the right number of loadstart events were fired.
|
// Verify the right number of loadstart events were fired.
|
||||||
if (e.type == 'loadstop' || e.type == 'loaderror') {
|
if (e.type === 'loadstop' || e.type === 'loaderror') {
|
||||||
if (e.url != lastLoadStartURL) {
|
if (e.url !== lastLoadStartURL) {
|
||||||
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
|
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
if (numExpectedRedirects === 0 && counts.loadstart !== 1) {
|
if (numExpectedRedirects === 0 && counts.loadstart !== 1) {
|
||||||
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
|
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
|
||||||
if (!(e.type == 'loaderror' && counts.loadstart === 0)) {
|
if (!(e.type === 'loaderror' && counts.loadstart === 0)) {
|
||||||
alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')');
|
alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
} else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) {
|
} else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) {
|
||||||
alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart);
|
alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
wasReset = true;
|
wasReset = true;
|
||||||
numExpectedRedirects = 0;
|
numExpectedRedirects = 0;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
// Verify that loadend / loaderror was called.
|
// Verify that loadend / loaderror was called.
|
||||||
if (e.type == 'exit') {
|
if (e.type === 'exit') {
|
||||||
var numStopEvents = counts.loadstop + counts.loaderror;
|
var numStopEvents = counts.loadstop + counts.loaderror;
|
||||||
if (numStopEvents === 0 && !wasReset) {
|
if (numStopEvents === 0 && !wasReset) {
|
||||||
alert('Unexpected: browser closed without a loadstop or loaderror.');
|
alert('Unexpected: browser closed without a loadstop or loaderror.'); // eslint-disable-line no-undef
|
||||||
} else if (numStopEvents > 1) {
|
} else if (numStopEvents > 1) {
|
||||||
alert('Unexpected: got multiple loadstop/loaderror events.');
|
alert('Unexpected: got multiple loadstop/loaderror events.'); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,12 +238,10 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
doOpen(url, target, params, numExpectedRedirects, true);
|
doOpen(url, target, params, numExpectedRedirects, true);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
if (wasClobbered) {
|
if (wasClobbered) {
|
||||||
window.open = originalFunc;
|
window.open = originalFunc;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
console.log('just delete, to restore open from prototype');
|
console.log('just delete, to restore open from prototype');
|
||||||
delete window.open;
|
delete window.open;
|
||||||
}
|
}
|
||||||
@ -256,10 +252,10 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
var iab = doOpen(url, '_blank', 'location=yes');
|
var iab = doOpen(url, '_blank', 'location=yes');
|
||||||
var callback = function (results) {
|
var callback = function (results) {
|
||||||
if (results && results.length === 0) {
|
if (results && results.length === 0) {
|
||||||
alert('Results verified');
|
alert('Results verified'); // eslint-disable-line no-undef
|
||||||
} else {
|
} else {
|
||||||
console.log(results);
|
console.log(results);
|
||||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results));
|
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (cssUrl) {
|
if (cssUrl) {
|
||||||
@ -280,10 +276,10 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
iab.addEventListener('loadstop', function (event) {
|
iab.addEventListener('loadstop', function (event) {
|
||||||
iab.executeScript({ file: jsUrl }, useCallback && function (results) {
|
iab.executeScript({ file: jsUrl }, useCallback && function (results) {
|
||||||
if (results && results.length === 0) {
|
if (results && results.length === 0) {
|
||||||
alert('Results verified');
|
alert('Results verified'); // eslint-disable-line no-undef
|
||||||
} else {
|
} else {
|
||||||
console.log(results);
|
console.log(results);
|
||||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results));
|
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -296,33 +292,33 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
'})()';
|
'})()';
|
||||||
iab.executeScript({ code: code }, useCallback && function (results) {
|
iab.executeScript({ code: code }, useCallback && function (results) {
|
||||||
if (results && results.length === 1 && results[0] === 'abc') {
|
if (results && results.length === 1 && results[0] === 'abc') {
|
||||||
alert('Results verified');
|
alert('Results verified'); // eslint-disable-line no-undef
|
||||||
} else {
|
} else {
|
||||||
console.log(results);
|
console.log(results);
|
||||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results));
|
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var hiddenwnd = null;
|
var hiddenwnd = null;
|
||||||
var loadlistener = function (event) { alert('background window loaded '); };
|
var loadlistener = function (event) { alert('background window loaded '); }; // eslint-disable-line no-undef
|
||||||
function openHidden (url, startHidden) {
|
function openHidden (url, startHidden) {
|
||||||
var shopt = (startHidden) ? 'hidden=yes' : '';
|
var shopt = (startHidden) ? 'hidden=yes' : '';
|
||||||
hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt);
|
hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt);
|
||||||
if (!hiddenwnd) {
|
if (!hiddenwnd) {
|
||||||
alert('cordova.InAppBrowser.open returned ' + hiddenwnd);
|
alert('cordova.InAppBrowser.open returned ' + hiddenwnd); // eslint-disable-line no-undef
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
|
if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
|
||||||
}
|
}
|
||||||
function showHidden () {
|
function showHidden () {
|
||||||
if (!!hiddenwnd) {
|
if (hiddenwnd) {
|
||||||
hiddenwnd.show();
|
hiddenwnd.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function closeHidden () {
|
function closeHidden () {
|
||||||
if (!!hiddenwnd) {
|
if (hiddenwnd) {
|
||||||
hiddenwnd.removeEventListener('loadstop', loadlistener);
|
hiddenwnd.removeEventListener('loadstop', loadlistener);
|
||||||
hiddenwnd.close();
|
hiddenwnd.close();
|
||||||
hiddenwnd = null;
|
hiddenwnd = null;
|
||||||
@ -483,16 +479,16 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
|
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("user-agent").textContent = navigator.userAgent;
|
document.getElementById('user-agent').textContent = navigator.userAgent;
|
||||||
|
|
||||||
// we are already in cdvtests directory
|
// we are already in cdvtests directory
|
||||||
var basePath = 'iab-resources/';
|
var basePath = 'iab-resources/';
|
||||||
var localhtml = basePath + 'local.html',
|
var localhtml = basePath + 'local.html';
|
||||||
localpdf = basePath + 'local.pdf',
|
var localpdf = basePath + 'local.pdf';
|
||||||
injecthtml = basePath + 'inject.html',
|
var injecthtml = basePath + 'inject.html';
|
||||||
injectjs = isWindows ? basePath + 'inject.js' : 'inject.js',
|
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
|
||||||
injectcss = isWindows ? basePath + 'inject.css' : 'inject.css',
|
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
|
||||||
videohtml = basePath + 'video.html';
|
var videohtml = basePath + 'video.html';
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
createActionButton('target=Default', function () {
|
createActionButton('target=Default', function () {
|
||||||
|
@ -47,13 +47,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
close: function (eventname) {
|
close: function (eventname) {
|
||||||
exec(null, null, "InAppBrowser", "close", []);
|
exec(null, null, 'InAppBrowser', 'close', []);
|
||||||
},
|
},
|
||||||
show: function (eventname) {
|
show: function (eventname) {
|
||||||
exec(null, null, "InAppBrowser", "show", []);
|
exec(null, null, 'InAppBrowser', 'show', []);
|
||||||
},
|
},
|
||||||
hide: function (eventname) {
|
hide: function (eventname) {
|
||||||
exec(null, null, "InAppBrowser", "hide", []);
|
exec(null, null, 'InAppBrowser', 'hide', []);
|
||||||
},
|
},
|
||||||
addEventListener: function (eventname, f) {
|
addEventListener: function (eventname, f) {
|
||||||
if (eventname in this.channels) {
|
if (eventname in this.channels) {
|
||||||
@ -68,9 +68,9 @@
|
|||||||
|
|
||||||
executeScript: function (injectDetails, cb) {
|
executeScript: function (injectDetails, cb) {
|
||||||
if (injectDetails.code) {
|
if (injectDetails.code) {
|
||||||
exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]);
|
exec(cb, null, 'InAppBrowser', 'injectScriptCode', [injectDetails.code, !!cb]);
|
||||||
} else if (injectDetails.file) {
|
} else if (injectDetails.file) {
|
||||||
exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]);
|
exec(cb, null, 'InAppBrowser', 'injectScriptFile', [injectDetails.file, !!cb]);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('executeScript requires exactly one of code or file to be specified');
|
throw new Error('executeScript requires exactly one of code or file to be specified');
|
||||||
}
|
}
|
||||||
@ -78,9 +78,9 @@
|
|||||||
|
|
||||||
insertCSS: function (injectDetails, cb) {
|
insertCSS: function (injectDetails, cb) {
|
||||||
if (injectDetails.code) {
|
if (injectDetails.code) {
|
||||||
exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]);
|
exec(cb, null, 'InAppBrowser', 'injectStyleCode', [injectDetails.code, !!cb]);
|
||||||
} else if (injectDetails.file) {
|
} else if (injectDetails.file) {
|
||||||
exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]);
|
exec(cb, null, 'InAppBrowser', 'injectStyleFile', [injectDetails.file, !!cb]);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('insertCSS requires exactly one of code or file to be specified');
|
throw new Error('insertCSS requires exactly one of code or file to be specified');
|
||||||
}
|
}
|
||||||
@ -106,9 +106,9 @@
|
|||||||
iab._eventHandler(eventname);
|
iab._eventHandler(eventname);
|
||||||
};
|
};
|
||||||
|
|
||||||
strWindowFeatures = strWindowFeatures || "";
|
strWindowFeatures = strWindowFeatures || '';
|
||||||
|
|
||||||
exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
|
exec(cb, cb, 'InAppBrowser', 'open', [strUrl, strWindowName, strWindowFeatures]);
|
||||||
return iab;
|
return iab;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -45,24 +45,24 @@ var IAB = {
|
|||||||
} */
|
} */
|
||||||
},
|
},
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0];
|
||||||
target = args[1],
|
var target = args[1];
|
||||||
url,
|
var url;
|
||||||
elem;
|
var elem;
|
||||||
|
|
||||||
if (target === "_system") {
|
if (target === '_system') {
|
||||||
url = new Windows.Foundation.Uri(strUrl);
|
url = new Windows.Foundation.Uri(strUrl);
|
||||||
Windows.System.Launcher.launchUriAsync(url);
|
Windows.System.Launcher.launchUriAsync(url);
|
||||||
} else if (target === "_blank") {
|
} else if (target === '_blank') {
|
||||||
if (!browserWrap) {
|
if (!browserWrap) {
|
||||||
browserWrap = document.createElement("div");
|
browserWrap = document.createElement('div');
|
||||||
browserWrap.style.position = "absolute";
|
browserWrap.style.position = 'absolute';
|
||||||
browserWrap.style.width = (window.innerWidth - 80) + "px";
|
browserWrap.style.width = (window.innerWidth - 80) + 'px';
|
||||||
browserWrap.style.height = (window.innerHeight - 80) + "px";
|
browserWrap.style.height = (window.innerHeight - 80) + 'px';
|
||||||
browserWrap.style.borderWidth = "40px";
|
browserWrap.style.borderWidth = '40px';
|
||||||
browserWrap.style.borderStyle = "solid";
|
browserWrap.style.borderStyle = 'solid';
|
||||||
browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
|
browserWrap.style.borderColor = 'rgba(0,0,0,0.25)';
|
||||||
browserWrap.style.zIndex = "9999999";
|
browserWrap.style.zIndex = '9999999';
|
||||||
|
|
||||||
browserWrap.onclick = function () {
|
browserWrap.onclick = function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -74,33 +74,31 @@ var IAB = {
|
|||||||
}
|
}
|
||||||
var localFile = (strUrl.indexOf('ms-appdata:///') > -1);
|
var localFile = (strUrl.indexOf('ms-appdata:///') > -1);
|
||||||
if (localFile) {
|
if (localFile) {
|
||||||
elem = document.createElement("x-ms-webview");
|
elem = document.createElement('x-ms-webview');
|
||||||
elem.style.width = (window.innerWidth - 80) + "px";
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
||||||
elem.style.height = (window.innerHeight - 80) + "px";
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
||||||
elem.style.borderWidth = "0px";
|
elem.style.borderWidth = '0px';
|
||||||
elem.name = "targetFrame";
|
elem.name = 'targetFrame';
|
||||||
elem.src = strUrl;
|
elem.src = strUrl;
|
||||||
|
|
||||||
window.addEventListener("resize", function () {
|
window.addEventListener('resize', function () {
|
||||||
if (browserWrap && elem) {
|
if (browserWrap && elem) {
|
||||||
elem.style.width = (window.innerWidth - 80) + "px";
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
||||||
elem.style.height = (window.innerHeight - 80) + "px";
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
elem = document.createElement("iframe");
|
elem = document.createElement('iframe');
|
||||||
elem.style.width = (window.innerWidth - 80) + "px";
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
||||||
elem.style.height = (window.innerHeight - 80) + "px";
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
||||||
elem.style.borderWidth = "0px";
|
elem.style.borderWidth = '0px';
|
||||||
elem.name = "targetFrame";
|
elem.name = 'targetFrame';
|
||||||
elem.src = strUrl;
|
elem.src = strUrl;
|
||||||
|
|
||||||
|
window.addEventListener('resize', function () {
|
||||||
window.addEventListener("resize", function () {
|
|
||||||
if (browserWrap && elem) {
|
if (browserWrap && elem) {
|
||||||
elem.style.width = (window.innerWidth - 80) + "px";
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
||||||
elem.style.height = (window.innerHeight - 80) + "px";
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -111,7 +109,6 @@ var IAB = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// var object = new WinJS.UI.HtmlControl(elem, { uri: strUrl });
|
// var object = new WinJS.UI.HtmlControl(elem, { uri: strUrl });
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
injectScriptCode: function (code, bCB) {
|
injectScriptCode: function (code, bCB) {
|
||||||
@ -126,5 +123,4 @@ var IAB = {
|
|||||||
|
|
||||||
module.exports = IAB;
|
module.exports = IAB;
|
||||||
|
|
||||||
|
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|
||||||
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user