[go: nahoru, domu]

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

Add eslint and update noVNC to ES6 #1013

Merged
merged 3 commits into from
May 25, 2018
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
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
"no-constant-condition": ["error", { "checkLoops": false }],
"no-var": "error"
}
}
7 changes: 3 additions & 4 deletions app/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
// native support in the browsers, so that our error handler
// can catch script-loading errors.


(function(){
"use strict";

// Fallback for all uncought errors
function handleError (event, err) {
try {
var msg = document.getElementById('noVNC_fallback_errormsg');
const msg = document.getElementById('noVNC_fallback_errormsg');

// Only show the initial error
if (msg.hasChildNodes()) {
return false;
}

var div = document.createElement("div");
let div = document.createElement("div");
div.classList.add('noVNC_message');
div.appendChild(document.createTextNode(event.message));
msg.appendChild(div);

if (event.filename) {
div = document.createElement("div");
div.className = 'noVNC_location';
var text = event.filename;
let text = event.filename;
if (event.lineno !== undefined) {
text += ":" + event.lineno;
if (event.colno !== undefined) {
Expand Down
47 changes: 22 additions & 25 deletions app/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@ export function Localizer() {
Localizer.prototype = {
// Configure suitable language based on user preferences
setup: function (supportedLanguages) {
var userLanguages;

this.language = 'en'; // Default: US English

/*
* Navigator.languages only available in Chrome (32+) and FireFox (32+)
* Fall back to navigator.language for other browsers
*/
let userLanguages;
if (typeof window.navigator.languages == 'object') {
userLanguages = window.navigator.languages;
} else {
userLanguages = [navigator.language || navigator.userLanguage];
}

for (var i = 0;i < userLanguages.length;i++) {
var userLang = userLanguages[i];
userLang = userLang.toLowerCase();
userLang = userLang.replace("_", "-");
userLang = userLang.split("-");
for (let i = 0;i < userLanguages.length;i++) {
const userLang = userLanguages[i]
.toLowerCase()
.replace("_", "-")
.split("-");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should move this to a helper function instead? Avoids this churn, and makes the const declaration more clear.


// Built-in default?
if ((userLang[0] === 'en') &&
Expand All @@ -48,11 +47,11 @@ Localizer.prototype = {
}

// First pass: perfect match
for (var j = 0;j < supportedLanguages.length;j++) {
var supLang = supportedLanguages[j];
supLang = supLang.toLowerCase();
supLang = supLang.replace("_", "-");
supLang = supLang.split("-");
for (let j = 0; j < supportedLanguages.length; j++) {
const supLang = supportedLanguages[j]
.toLowerCase()
.replace("_", "-")
.split("-");

if (userLang[0] !== supLang[0])
continue;
Expand All @@ -64,11 +63,11 @@ Localizer.prototype = {
}

// Second pass: fallback
for (var j = 0;j < supportedLanguages.length;j++) {
supLang = supportedLanguages[j];
supLang = supLang.toLowerCase();
supLang = supLang.replace("_", "-");
supLang = supLang.split("-");
for (let j = 0;j < supportedLanguages.length;j++) {
const supLang = supportedLanguages[j]
.toLowerCase()
.replace("_", "-")
.split("-");

if (userLang[0] !== supLang[0])
continue;
Expand All @@ -93,21 +92,19 @@ Localizer.prototype = {
// Traverses the DOM and translates relevant fields
// See https://html.spec.whatwg.org/multipage/dom.html#attr-translate
translateDOM: function () {
var self = this;
const self = this;
function process(elem, enabled) {
function isAnyOf(searchElement, items) {
return items.indexOf(searchElement) !== -1;
}

function translateAttribute(elem, attr) {
var str = elem.getAttribute(attr);
str = self.get(str);
const str = self.get(elem.getAttribute(attr));
elem.setAttribute(attr, str);
}

function translateTextNode(node) {
var str = node.data.trim();
str = self.get(str);
const str = self.get(node.data.trim());
node.data = str;
}

Expand Down Expand Up @@ -152,8 +149,8 @@ Localizer.prototype = {
}
}

for (var i = 0;i < elem.childNodes.length;i++) {
var node = elem.childNodes[i];
for (let i = 0; i < elem.childNodes.length; i++) {
const node = elem.childNodes[i];
if (node.nodeType === node.ELEMENT_NODE) {
process(node, enabled);
} else if (node.nodeType === node.TEXT_NODE && enabled) {
Expand All @@ -166,5 +163,5 @@ Localizer.prototype = {
},
};

export var l10n = new Localizer();
export const l10n = new Localizer();
export default l10n.get.bind(l10n);
Loading