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

Upgrade and fix webmap #281

Merged
merged 18 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from 16 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
193 changes: 100 additions & 93 deletions [web]/ajax/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,148 +59,154 @@

if (!Object.prototype.toJSONString) {

Array.prototype.toJSONString = function () {
var a = [], // The array holding the member texts.
i, // Loop counter.
l = this.length,
v; // The value to be stringified.
Object.defineProperty(Array.prototype, 'toJSONString', {
enumerable: false,
value: function () {
let a = [], // The array holding the member texts.
i, // Loop counter.
l = this.length,
v; // The value to be stringified.


// For each value in this array...

for (i = 0; i < l; i += 1) {
v = this[i];
switch (typeof v) {
case 'object':
for (i = 0; i < l; i += 1) {
v = this[i];
switch (typeof v) {
case 'object':

// Serialize a JavaScript object value. Ignore objects thats lack the
// toJSONString method. Due to a specification error in ECMAScript,
// typeof null is 'object', so watch out for that case.

if (v) {
if (typeof v.toJSONString === 'function') {
a.push(v.toJSONString());
if (v) {
if (typeof v.toJSONString === 'function') {
a.push(v.toJSONString());
}
} else {
a.push('null');
}
} else {
a.push('null');
}
break;
break;

case 'string':
case 'number':
case 'boolean':
a.push(v.toJSONString());
case 'string':
case 'number':
case 'boolean':
a.push(v.toJSONString());

// Values without a JSON representation are ignored.

}
}
}

// Join all of the member texts together and wrap them in brackets.

return '[' + a.join(',') + ']';
};


Boolean.prototype.toJSONString = function () {
return String(this);
};
return '[' + a.join(',') + ']';
},
});

Object.defineProperty(Boolean.prototype, 'toJSONString', {
enumerable: false,
value: function () {
return String(this);
},
});

Date.prototype.toJSONString = function () {
Object.defineProperty(Date.prototype, 'toJSONString', {
enumerable: false,
value: function () {

// Ultimately, this method will be equivalent to the date.toISOString method.

function f(n) {
function f(n) {

// Format integers to have at least two digits.

return n < 10 ? '0' + n : n;
}

return '"' + this.getFullYear() + '-' +
f(this.getMonth() + 1) + '-' +
f(this.getDate()) + 'T' +
f(this.getHours()) + ':' +
f(this.getMinutes()) + ':' +
f(this.getSeconds()) + '"';
};
return n < 10 ? '0' + n : n;
}

return '"' + this.getFullYear() + '-' +
f(this.getMonth() + 1) + '-' +
f(this.getDate()) + 'T' +
f(this.getHours()) + ':' +
f(this.getMinutes()) + ':' +
f(this.getSeconds()) + '"';
},
});

Number.prototype.toJSONString = function () {
Object.defineProperty(Number.prototype, 'toJSONString', {
enumerable: false,
value: function () {

// JSON numbers must be finite. Encode non-finite numbers as null.

return isFinite(this) ? String(this) : 'null';
};

return isFinite(this) ? String(this) : 'null';
},
});

Object.prototype.toJSONString = function () {
var a = [], // The array holding the member texts.
k, // The current key.
v; // The current value.
Object.defineProperty(Object.prototype, 'toJSONString', {
enumerable: false,
value: function () {
let a = [], // The array holding the member texts.
k, // The current key.
v; // The current value.

// Iterate through all of the keys in the object, ignoring the proto chain.

for (k in this) {
if (this.hasOwnProperty(k)) {
v = this[k];
switch (typeof v) {
case 'object':
for (k in this) {
if (this.hasOwnProperty(k)) {
v = this[k];
switch (typeof v) {
case 'object':

// Serialize a JavaScript object value. Ignore objects that lack the
// toJSONString method. Due to a specification error in ECMAScript,
// typeof null is 'object', so watch out for that case.

if (v) {
if (typeof v.toJSONString === 'function') {
a.push(k.toJSONString() + ':' + v.toJSONString());
if (v) {
if (typeof v.toJSONString === 'function') {
a.push(k.toJSONString() + ':' + v.toJSONString());
}
} else {
a.push(k.toJSONString() + ':null');
}
} else {
a.push(k.toJSONString() + ':null');
}
break;
break;

case 'string':
case 'number':
case 'boolean':
a.push(k.toJSONString() + ':' + v.toJSONString());
case 'string':
case 'number':
case 'boolean':
a.push(k.toJSONString() + ':' + v.toJSONString());

// Values without a JSON representation are ignored.

}
}
}
}

// Join all of the member texts together and wrap them in braces.

return '{' + a.join(',') + '}';
};


(function (s) {

// Augment String.prototype. We do this in an immediate anonymous function to
// avoid defining global variables.
return '{' + a.join(',') + '}';
}
});

// m is a table of character substitutions.

var m = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
};

const m = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
};

s.parseJSON = function (filter) {
var j;
Object.defineProperty(String.prototype, 'parseJSON', {
enumerable: false,
value: function (filter) {
let j;

function walk(k, v) {
var i;
let i;
if (v && typeof v === 'object') {
for (i in v) {
if (v.hasOwnProperty(i)) {
Expand Down Expand Up @@ -242,19 +248,20 @@ if (!Object.prototype.toJSONString) {
j = walk('', j);
}
return j;
};


s.toJSONString = function () {
},
});

Object.defineProperty(String.prototype, 'toJSONString', {
enumerable: false,
value: function () {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can simply slap some quotes around it.
// Otherwise we must also replace the offending characters with safe
// sequences.

if (/["\\\x00-\x1f]/.test(this)) {
return '"' + this.replace(/([\x00-\x1f\\"])/g, function (a, b) {
var c = m[b];
let c = m[b];
if (c) {
return c;
}
Expand All @@ -265,6 +272,6 @@ if (!Object.prototype.toJSONString) {
}) + '"';
}
return '"' + this + '"';
};
})(String.prototype);
},
});
}
22 changes: 22 additions & 0 deletions [web]/webmap/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is for unifying the coding style for different editors and IDEs
patrikjuvonen marked this conversation as resolved.
Show resolved Hide resolved
# editorconfig.org

# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = crlf
indent_size = 2
indent_style = space
insert_final_newline = true

# Get rid of whitespace to avoid diffs with a bunch of EOL changes
trim_trailing_whitespace = true

[*.md]
max_line_length = 0
trim_trailing_whitespace = false

[*.css]
indent_size = 4
7 changes: 7 additions & 0 deletions [web]/webmap/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
patrikjuvonen marked this conversation as resolved.
Show resolved Hide resolved
"bracketSpacing": true,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always",
"jsxBracketSameLine": true
}
Loading