CB-12895 : added eslint and removed jshint

This commit is contained in:
Audrey So
2017-06-12 10:34:08 -07:00
parent 7611645469
commit 902427525f
12 changed files with 350 additions and 362 deletions
+76 -79
View File
@@ -29,43 +29,43 @@ var browserWrap,
forwardButton,
closeButton;
function attachNavigationEvents(element, callback) {
function attachNavigationEvents (element, callback) {
var onError = function () {
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) {
// 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 {
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) {
// 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 {
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) {
// 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("abort", onError);
element.addEventListener('error', onError);
element.addEventListener('abort', onError);
}
var IAB = {
close: function (win, lose) {
if (browserWrap) {
// 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 = null;
@@ -75,34 +75,34 @@ var IAB = {
show: function (win, lose) {
if (browserWrap) {
browserWrap.style.display = "block";
browserWrap.style.display = 'block';
}
},
open: function (win, lose, args) {
var strUrl = args[0],
target = args[1],
features = args[2];
var strUrl = args[0];
var target = args[1];
var features = args[2];
IAB._win = win;
if (target === "_self" || !target) {
if (target === '_self' || !target) {
window.location = strUrl;
} else if (target === "_system") {
modulemapper.getOriginalSymbol(window, 'window.open').call(window, strUrl, "_blank");
} else if (target === '_system') {
modulemapper.getOriginalSymbol(window, 'window.open').call(window, strUrl, '_blank');
} else {
// "_blank" or anything else
if (!browserWrap) {
browserWrap = document.createElement("div");
browserWrap.style.position = "absolute";
browserWrap.style.top = "0";
browserWrap.style.left = "0";
browserWrap.style.boxSizing = "border-box";
browserWrap.style.borderWidth = "40px";
browserWrap.style.width = "100vw";
browserWrap.style.height = "100vh";
browserWrap.style.borderStyle = "solid";
browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
browserWrap = document.createElement('div');
browserWrap.style.position = 'absolute';
browserWrap.style.top = '0';
browserWrap.style.left = '0';
browserWrap.style.boxSizing = 'border-box';
browserWrap.style.borderWidth = '40px';
browserWrap.style.width = '100vw';
browserWrap.style.height = '100vh';
browserWrap.style.borderStyle = 'solid';
browserWrap.style.borderColor = 'rgba(0,0,0,0.25)';
browserWrap.onclick = function () {
setTimeout(function () {
@@ -113,71 +113,68 @@ var IAB = {
document.body.appendChild(browserWrap);
}
if (features.indexOf("hidden=yes") !== -1) {
browserWrap.style.display = "none";
if (features.indexOf('hidden=yes') !== -1) {
browserWrap.style.display = 'none';
}
popup = document.createElement("iframe");
popup.style.borderWidth = "0px";
popup.style.width = "100%";
popup = document.createElement('iframe');
popup.style.borderWidth = '0px';
popup.style.width = '100%';
browserWrap.appendChild(popup);
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
popup.style.height = "calc(100% - 60px)";
popup.style.marginBottom = "-4px";
if (features.indexOf('location=yes') !== -1 || features.indexOf('location') === -1) {
popup.style.height = 'calc(100% - 60px)';
popup.style.marginBottom = '-4px';
navigationButtonsDiv = document.createElement("div");
navigationButtonsDiv.style.height = "60px";
navigationButtonsDiv.style.backgroundColor = "#404040";
navigationButtonsDiv.style.zIndex = "999";
navigationButtonsDiv = document.createElement('div');
navigationButtonsDiv.style.height = '60px';
navigationButtonsDiv.style.backgroundColor = '#404040';
navigationButtonsDiv.style.zIndex = '999';
navigationButtonsDiv.onclick = function (e) {
e.cancelBubble = true;
};
navigationButtonsDivInner = document.createElement("div");
navigationButtonsDivInner.style.paddingTop = "10px";
navigationButtonsDivInner.style.height = "50px";
navigationButtonsDivInner.style.width = "160px";
navigationButtonsDivInner.style.margin = "0 auto";
navigationButtonsDivInner.style.backgroundColor = "#404040";
navigationButtonsDivInner.style.zIndex = "999";
navigationButtonsDivInner = document.createElement('div');
navigationButtonsDivInner.style.paddingTop = '10px';
navigationButtonsDivInner.style.height = '50px';
navigationButtonsDivInner.style.width = '160px';
navigationButtonsDivInner.style.margin = '0 auto';
navigationButtonsDivInner.style.backgroundColor = '#404040';
navigationButtonsDivInner.style.zIndex = '999';
navigationButtonsDivInner.onclick = function (e) {
e.cancelBubble = true;
};
backButton = document.createElement('button');
backButton.style.width = '40px';
backButton.style.height = '40px';
backButton.style.borderRadius = '40px';
backButton = document.createElement("button");
backButton.style.width = "40px";
backButton.style.height = "40px";
backButton.style.borderRadius = "40px";
backButton.innerHTML = "←";
backButton.addEventListener("click", function (e) {
if (popup.canGoBack)
popup.goBack();
backButton.innerHTML = '←';
backButton.addEventListener('click', function (e) {
if (popup.canGoBack) { popup.goBack(); }
});
forwardButton = document.createElement("button");
forwardButton.style.marginLeft = "20px";
forwardButton.style.width = "40px";
forwardButton.style.height = "40px";
forwardButton.style.borderRadius = "40px";
forwardButton = document.createElement('button');
forwardButton.style.marginLeft = '20px';
forwardButton.style.width = '40px';
forwardButton.style.height = '40px';
forwardButton.style.borderRadius = '40px';
forwardButton.innerHTML = "→";
forwardButton.addEventListener("click", function (e) {
if (popup.canGoForward)
popup.goForward();
forwardButton.innerHTML = '→';
forwardButton.addEventListener('click', function (e) {
if (popup.canGoForward) { popup.goForward(); }
});
closeButton = document.createElement("button");
closeButton.style.marginLeft = "20px";
closeButton.style.width = "40px";
closeButton.style.height = "40px";
closeButton.style.borderRadius = "40px";
closeButton = document.createElement('button');
closeButton.style.marginLeft = '20px';
closeButton.style.width = '40px';
closeButton.style.height = '40px';
closeButton.style.borderRadius = '40px';
closeButton.innerHTML = "✖";
closeButton.addEventListener("click", function (e) {
closeButton.innerHTML = '✖';
closeButton.addEventListener('click', function (e) {
setTimeout(function () {
IAB.close();
}, 0);
@@ -194,7 +191,7 @@ var IAB = {
browserWrap.appendChild(navigationButtonsDiv);
} else {
popup.style.height = "100%";
popup.style.height = '100%';
}
// start listening for navigation events
@@ -205,8 +202,8 @@ var IAB = {
},
injectScriptCode: function (win, fail, args) {
var code = args[0],
hasCallback = args[1];
var code = args[0];
var hasCallback = args[1];
if (browserWrap && popup) {
try {
@@ -214,7 +211,7 @@ var IAB = {
if (hasCallback) {
win([]);
}
} catch(e) {
} catch (e) {
console.error('Error occured while trying to injectScriptCode: ' + JSON.stringify(e));
}
}
@@ -226,7 +223,7 @@ var IAB = {
if (fail) {
fail(msg);
}
},
},
injectStyleCode: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented';
@@ -247,4 +244,4 @@ var IAB = {
module.exports = IAB;
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
+21 -22
View File
@@ -32,7 +32,7 @@ var IABExecs = {
if (browserWrap) {
browserWrap.parentNode.removeChild(browserWrap);
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) {
var strUrl = args[0],
target = args[1],
features_string = args[2] || "location=yes", //location=yes is default
features = {};
var strUrl = args[0];
var target = args[1];
var features_string = args[2] || 'location=yes'; // location=yes is default
var features = {};
var features_list = features_string.split(',');
features_list.forEach(function(feature) {
features_list.forEach(function (feature) {
var tup = feature.split('=');
if (tup[1] == 'yes') {
if (tup[1] === 'yes') {
tup[1] = true;
} else if (tup[1] == 'no') {
} else if (tup[1] === 'no') {
tup[1] = false;
} else {
var number = parseInt(tup[1]);
@@ -68,8 +68,7 @@ var IABExecs = {
}
features[tup[0]] = tup[1];
});
function updateIframeSizeNoLocation() {
function updateIframeSizeNoLocation () {
browserWrap.style.width = window.innerWidth + 'px';
browserWrap.style.height = window.innerHeight + 'px';
browserWrap.style.zIndex = '999999999';
@@ -117,7 +116,7 @@ var IABExecs = {
var checkForwardBackward = function () {
var backReq = browserElem.getCanGoBack();
backReq.onsuccess = function() {
backReq.onsuccess = function () {
if (this.result) {
back.classList.remove('disabled');
} else {
@@ -125,7 +124,7 @@ var IABExecs = {
}
};
var forwardReq = browserElem.getCanGoForward();
forwardReq.onsuccess = function() {
forwardReq.onsuccess = function () {
if (this.result) {
forward.classList.remove('disabled');
} else {
@@ -158,21 +157,21 @@ var IABExecs = {
browserWrap.appendChild(browserElem);
document.body.appendChild(browserWrap);
//we use mozbrowserlocationchange instead of mozbrowserloadstart to get the url
browserElem.addEventListener('mozbrowserlocationchange', function(e){
// we use mozbrowserlocationchange instead of mozbrowserloadstart to get the url
browserElem.addEventListener('mozbrowserlocationchange', function (e) {
win({
type:'loadstart',
url : e.detail
type: 'loadstart',
url: e.detail
});
}, false);
browserElem.addEventListener('mozbrowserloadend', function(e){
win({type:'loadstop'});
browserElem.addEventListener('mozbrowserloadend', function (e) {
win({type: 'loadstop'});
}, false);
browserElem.addEventListener('mozbrowsererror', function(e){
win({type:'loaderror'});
browserElem.addEventListener('mozbrowsererror', function (e) {
win({type: 'loaderror'});
}, false);
browserElem.addEventListener('mozbrowserclose', function(e){
win({type:'exit'});
browserElem.addEventListener('mozbrowserclose', function (e) {
win({type: 'exit'});
}, false);
} else {
window.location = strUrl;
+4 -5
View File
@@ -19,14 +19,13 @@
*
*/
/* jshint -W061 */
/* global oxide */
oxide.addMessageHandler("EXECUTE", function(msg) {
oxide.addMessageHandler('EXECUTE', function (msg) {
var code = msg.args.code;
try {
msg.reply({result: eval(code)});
} catch(e) {
msg.error("Code threw exception: \"" + e + "\"");
msg.reply({result: eval(code)}); // eslint-disable-line no-eval
} catch (e) {
msg.error('Code threw exception: "' + e + '"');
}
});
+95 -96
View File
@@ -1,4 +1,4 @@
/*
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,9 +21,10 @@
/* jslint sloppy:true */
/* global Windows:true, setImmediate */
/* eslint standard/no-callback-literal : 0 */
var cordova = require('cordova'),
urlutil = require('cordova/urlutil');
var cordova = require('cordova');
var urlutil = require('cordova/urlutil');
var browserWrap,
popup,
@@ -40,56 +41,56 @@ var browserWrap,
// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx
var isWebViewAvailable = cordova.platformId === 'windows';
function attachNavigationEvents(element, callback) {
function attachNavigationEvents (element, callback) {
if (isWebViewAvailable) {
element.addEventListener("MSWebViewNavigationStarting", function (e) {
callback({ type: "loadstart", url: e.uri}, {keepCallback: true} );
element.addEventListener('MSWebViewNavigationStarting', function (e) {
callback({ type: 'loadstart', url: e.uri }, {keepCallback: true});
});
element.addEventListener("MSWebViewNavigationCompleted", function (e) {
element.addEventListener('MSWebViewNavigationCompleted', function (e) {
if (e.isSuccess) {
callback({ type: "loadstop", url: e.uri }, { keepCallback: true });
callback({ type: 'loadstop', url: e.uri }, { keepCallback: true });
} 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.
// 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 (popup.canGoBack) {
backButton.removeAttribute("disabled");
backButton.removeAttribute('disabled');
} else {
backButton.setAttribute("disabled", "true");
backButton.setAttribute('disabled', 'true');
}
if (popup.canGoForward) {
forwardButton.removeAttribute("disabled");
forwardButton.removeAttribute('disabled');
} else {
forwardButton.setAttribute("disabled", "true");
forwardButton.setAttribute('disabled', 'true');
}
}
});
} else {
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 () {
callback({ type: "loadstart", url: this.contentWindow.location}, {keepCallback: true});
element.addEventListener('unload', function () {
callback({ type: 'loadstart', url: this.contentWindow.location }, {keepCallback: true});
});
element.addEventListener("load", function () {
callback({ type: "loadstop", url: this.contentWindow.location}, {keepCallback: true});
element.addEventListener('load', function () {
callback({ type: 'loadstop', url: this.contentWindow.location }, {keepCallback: true});
});
element.addEventListener("error", onError);
element.addEventListener("abort", onError);
element.addEventListener('error', onError);
element.addEventListener('abort', onError);
}
}
@@ -98,7 +99,7 @@ var IAB = {
setImmediate(function () {
if (browserWrap) {
if (navigationEventsCallback) {
navigationEventsCallback({ type: "exit" });
navigationEventsCallback({ type: 'exit' });
}
browserWrap.parentNode.removeChild(browserWrap);
@@ -107,52 +108,52 @@ var IAB = {
browserWrap = null;
popup = null;
document.removeEventListener("backbutton", hardwareBackCallback, false);
document.removeEventListener('backbutton', hardwareBackCallback, false);
}
});
},
show: function (win, lose) {
setImmediate(function () {
if (browserWrap) {
browserWrap.style.display = "block";
browserWrap.style.display = 'block';
}
});
},
hide: function (win, lose) {
if (browserWrap) {
browserWrap.style.display = "none";
browserWrap.style.display = 'none';
}
},
open: function (win, lose, args) {
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
setImmediate(function () {
var strUrl = args[0],
target = args[1],
features = args[2],
url;
var strUrl = args[0];
var target = args[1];
var features = args[2];
var url;
navigationEventsCallback = win;
if (target === "_system") {
if (target === '_system') {
url = new Windows.Foundation.Uri(strUrl);
Windows.System.Launcher.launchUriAsync(url);
} else if (target === "_self" || !target) {
} else if (target === '_self' || !target) {
window.location = strUrl;
} else {
// "_blank" or anything else
if (!browserWrap) {
var browserWrapStyle = document.createElement('link');
browserWrapStyle.rel = "stylesheet";
browserWrapStyle.type = "text/css";
browserWrapStyle.href = urlutil.makeAbsolute("/www/css/inappbrowser.css");
browserWrapStyle.rel = 'stylesheet';
browserWrapStyle.type = 'text/css';
browserWrapStyle.href = urlutil.makeAbsolute('/www/css/inappbrowser.css');
document.head.appendChild(browserWrapStyle);
browserWrap = document.createElement("div");
browserWrap.className = "inAppBrowserWrap";
browserWrap = document.createElement('div');
browserWrap.className = 'inAppBrowserWrap';
if (features.indexOf("fullscreen=yes") > -1) {
browserWrap.classList.add("inAppBrowserWrapFullscreen");
if (features.indexOf('fullscreen=yes') > -1) {
browserWrap.classList.add('inAppBrowserWrapFullscreen');
}
// Save body overflow style to be able to reset it back later
@@ -166,22 +167,22 @@ var IAB = {
document.body.appendChild(browserWrap);
// 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) {
browserWrap.style.display = "none";
if (features.indexOf('hidden=yes') !== -1) {
browserWrap.style.display = 'none';
}
popup = document.createElement(isWebViewAvailable ? "x-ms-webview" : "iframe");
if (popup instanceof HTMLIFrameElement) {
popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe');
if (popup instanceof HTMLIFrameElement) { // eslint-disable-line no-undef
// For iframe we need to override bacground color of parent element here
// otherwise pages without background color set will have transparent background
popup.style.backgroundColor = "white";
popup.style.backgroundColor = 'white';
}
popup.style.borderWidth = "0px";
popup.style.width = "100%";
popup.style.marginBottom = "-5px";
popup.style.borderWidth = '0px';
popup.style.width = '100%';
popup.style.marginBottom = '-5px';
browserWrap.appendChild(popup);
@@ -191,14 +192,14 @@ var IAB = {
}, 0);
};
if (features.indexOf("hardwareback=yes") > -1 || features.indexOf("hardwareback") === -1) {
if (features.indexOf('hardwareback=yes') > -1 || features.indexOf('hardwareback') === -1) {
hardwareBackCallback = function () {
if (browserWrap.style.display === 'none') {
// 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.
// 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.
throw 'Exit the app';
throw 'Exit the app'; // eslint-disable-line no-throw-literal
}
if (popup.canGoBack) {
@@ -207,59 +208,57 @@ var IAB = {
closeHandler();
}
};
} else if (features.indexOf("hardwareback=no") > -1) {
} else if (features.indexOf('hardwareback=no') > -1) {
hardwareBackCallback = function () {
if (browserWrap.style.display === 'none') {
// See comment above
throw 'Exit the app';
throw 'Exit the app'; // eslint-disable-line no-throw-literal
}
closeHandler();
};
}
document.addEventListener("backbutton", hardwareBackCallback, false);
document.addEventListener('backbutton', hardwareBackCallback, false);
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
popup.style.height = "calc(100% - 70px)";
if (features.indexOf('location=yes') !== -1 || features.indexOf('location') === -1) {
popup.style.height = 'calc(100% - 70px)';
navigationButtonsDiv = document.createElement("div");
navigationButtonsDiv.className = "inappbrowser-app-bar";
navigationButtonsDiv = document.createElement('div');
navigationButtonsDiv.className = 'inappbrowser-app-bar';
navigationButtonsDiv.onclick = function (e) {
e.cancelBubble = true;
};
navigationButtonsDivInner = document.createElement("div");
navigationButtonsDivInner.className = "inappbrowser-app-bar-inner";
navigationButtonsDivInner = document.createElement('div');
navigationButtonsDivInner.className = 'inappbrowser-app-bar-inner';
navigationButtonsDivInner.onclick = function (e) {
e.cancelBubble = true;
};
backButton = document.createElement("div");
backButton.innerText = "back";
backButton.className = "app-bar-action action-back";
backButton.addEventListener("click", function (e) {
if (popup.canGoBack)
popup.goBack();
backButton = document.createElement('div');
backButton.innerText = 'back';
backButton.className = 'app-bar-action action-back';
backButton.addEventListener('click', function (e) {
if (popup.canGoBack) { popup.goBack(); }
});
forwardButton = document.createElement("div");
forwardButton.innerText = "forward";
forwardButton.className = "app-bar-action action-forward";
forwardButton.addEventListener("click", function (e) {
if (popup.canGoForward)
popup.goForward();
forwardButton = document.createElement('div');
forwardButton.innerText = 'forward';
forwardButton.className = 'app-bar-action action-forward';
forwardButton.addEventListener('click', function (e) {
if (popup.canGoForward) { popup.goForward(); }
});
closeButton = document.createElement("div");
closeButton.innerText = "close";
closeButton.className = "app-bar-action action-close";
closeButton.addEventListener("click", closeHandler);
closeButton = document.createElement('div');
closeButton.innerText = 'close';
closeButton.className = 'app-bar-action action-close';
closeButton.addEventListener('click', closeHandler);
if (!isWebViewAvailable) {
// iframe navigation is not yet supported
backButton.setAttribute("disabled", "true");
forwardButton.setAttribute("disabled", "true");
backButton.setAttribute('disabled', 'true');
forwardButton.setAttribute('disabled', 'true');
}
navigationButtonsDivInner.appendChild(backButton);
@@ -269,14 +268,14 @@ var IAB = {
browserWrap.appendChild(navigationButtonsDiv);
} else {
popup.style.height = "100%";
popup.style.height = '100%';
}
// start listening for navigation events
attachNavigationEvents(popup, navigationEventsCallback);
if (isWebViewAvailable) {
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
strUrl = strUrl.replace('ms-appx://', 'ms-appx-web://');
}
popup.src = strUrl;
}
@@ -285,11 +284,11 @@ var IAB = {
injectScriptCode: function (win, fail, args) {
setImmediate(function () {
var code = args[0],
hasCallback = args[1];
var code = args[0];
var hasCallback = args[1];
if (isWebViewAvailable && browserWrap && popup) {
var op = popup.invokeScriptAsync("eval", code);
var op = popup.invokeScriptAsync('eval', code);
op.oncomplete = function (e) {
if (hasCallback) {
// return null if event target is unavailable by some reason
@@ -305,10 +304,10 @@ var IAB = {
injectScriptFile: function (win, fail, args) {
setImmediate(function () {
var filePath = args[0],
hasCallback = args[1];
var filePath = args[0];
var hasCallback = args[1];
if (!!filePath) {
if (filePath) {
filePath = urlutil.makeAbsolute(filePath);
}
@@ -317,8 +316,8 @@ var IAB = {
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) {
Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function(e) {
var op = popup.invokeScriptAsync('eval', code);
op.oncomplete = function (e) {
if (hasCallback) {
var result = [e.target.result];
win(result);
@@ -334,8 +333,8 @@ var IAB = {
injectStyleCode: function (win, fail, args) {
setImmediate(function () {
var code = args[0],
hasCallback = args[1];
var code = args[0];
var hasCallback = args[1];
if (isWebViewAvailable && browserWrap && popup) {
injectCSS(popup, code, hasCallback && win);
@@ -345,8 +344,8 @@ var IAB = {
injectStyleFile: function (win, fail, args) {
setImmediate(function () {
var filePath = args[0],
hasCallback = args[1];
var filePath = args[0];
var hasCallback = args[1];
filePath = filePath && urlutil.makeAbsolute(filePath);
@@ -368,11 +367,11 @@ var IAB = {
function injectCSS (webView, cssCode, callback) {
// This will automatically escape all thing that we need (quotes, slashes, etc.)
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);
var op = webView.invokeScriptAsync("eval", evalWrapper);
op.oncomplete = function() {
var op = webView.invokeScriptAsync('eval', evalWrapper);
op.oncomplete = function () {
if (callback) {
callback([]);
}
@@ -383,4 +382,4 @@ function injectCSS (webView, cssCode, callback) {
module.exports = IAB;
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
require('cordova/exec/proxy').add('InAppBrowser', module.exports);