Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(eslint): use cordova-eslint /w fix #747

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
extends: '@cordova/eslint-config/browser'

overrides:
- files: [tests/**/*.js]
extends: '@cordova/eslint-config/node-tests'
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"cordova-windows"
],
"scripts": {
"test": "npm run eslint",
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
"test": "npm run lint",
"lint": "eslint ."
},
"engines": {
"cordovaDependencies": {
Expand All @@ -54,12 +54,6 @@
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"devDependencies": {
"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"
"@cordova/eslint-config": "^3.0.0"
}
}
30 changes: 14 additions & 16 deletions src/browser/InAppBrowserProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,37 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

var modulemapper = require('cordova/modulemapper');

var browserWrap,
popup,
navigationButtonsDiv,
navigationButtonsDivInner,
backButton,
forwardButton,
closeButton;
var browserWrap, popup, navigationButtonsDiv, navigationButtonsDivInner, backButton, forwardButton, closeButton;

function attachNavigationEvents (element, callback) {
var onError = function () {
try {
callback({ type: 'loaderror', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
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}); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loaderror', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
}
};

element.addEventListener('pageshow', function () {
try {
callback({ type: 'loadstart', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
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}); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loadstart', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
}
});

element.addEventListener('load', function () {
try {
callback({ type: 'loadstop', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
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}); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loadstop', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
}
});

Expand Down Expand Up @@ -153,7 +147,9 @@ var IAB = {

backButton.innerHTML = '←';
backButton.addEventListener('click', function (e) {
if (popup.canGoBack) { popup.goBack(); }
if (popup.canGoBack) {
popup.goBack();
}
});

forwardButton = document.createElement('button');
Expand All @@ -164,7 +160,9 @@ var IAB = {

forwardButton.innerHTML = '→';
forwardButton.addEventListener('click', function (e) {
if (popup.canGoForward) { popup.goForward(); }
if (popup.canGoForward) {
popup.goForward();
}
});

closeButton = document.createElement('button');
Expand Down
74 changes: 48 additions & 26 deletions src/windows/InAppBrowserProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

/* jslint sloppy:true */
/* global Windows:true, setImmediate */
/* eslint standard/no-callback-literal : 0 */
/* eslint-disable standard/no-callback-literal */
/* global Windows, setImmediate */

var cordova = require('cordova');
var urlutil = require('cordova/urlutil');
Expand All @@ -44,21 +43,32 @@ var isWebViewAvailable = cordova.platformId === 'windows';
function attachNavigationEvents (element, callback) {
if (isWebViewAvailable) {
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) {
if (e.isSuccess) {
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) {
// 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) {
Expand All @@ -78,15 +88,15 @@ function attachNavigationEvents (element, callback) {
});
} 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});
callback({ type: 'loadstart', url: this.contentWindow.location }, { keepCallback: true });
});

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);
Expand Down Expand Up @@ -175,7 +185,8 @@ var IAB = {
}

popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe');
if (popup instanceof HTMLIFrameElement) { // eslint-disable-line no-undef
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';
Expand Down Expand Up @@ -240,14 +251,18 @@ var IAB = {
backButton.innerText = 'back';
backButton.className = 'app-bar-action action-back';
backButton.addEventListener('click', function (e) {
if (popup.canGoBack) { popup.goBack(); }
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(); }
if (popup.canGoForward) {
popup.goForward();
}
});

closeButton = document.createElement('div');
Expand Down Expand Up @@ -292,11 +307,11 @@ var IAB = {
op.oncomplete = function (e) {
if (hasCallback) {
// return null if event target is unavailable by some reason
var result = (e && e.target) ? [e.target.result] : [null];
var result = e && e.target ? [e.target.result] : [null];
win(result);
}
};
op.onerror = function () { };
op.onerror = function () {};
op.start();
}
});
Expand All @@ -323,7 +338,7 @@ var IAB = {
win(result);
}
};
op.onerror = function () { };
op.onerror = function () {};
op.start();
});
});
Expand Down Expand Up @@ -352,13 +367,18 @@ var IAB = {
if (isWebViewAvailable && browserWrap && popup) {
// CB-12364 getFileFromApplicationUriAsync does not support ms-appx-web
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file);
}).done(function (code) {
injectCSS(popup, code, hasCallback && win);
}, function () {
// no-op, just catch an error
});
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri)
.then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file);
})
.done(
function (code) {
injectCSS(popup, code, hasCallback && win);
},
function () {
// no-op, just catch an error
}
);
}
});
}
Expand All @@ -367,16 +387,18 @@ 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)'
.replace('%s', escapedCode);
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 () {
if (callback) {
callback([]);
}
};
op.onerror = function () { };
op.onerror = function () {};
op.start();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/resources/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
*/

var d = document.getElementById('header');
d.innerHTML = 'Script file successfully injected';
Loading