Switch to curly style for if/else statements

This commit is contained in:
David Larlet 2023-09-25 11:42:03 -04:00
parent 27e8fd0cac
commit f2a25d3c91
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
17 changed files with 1682 additions and 369 deletions

View file

@ -1,6 +1,8 @@
trailingComma: "es5"
trailingComma: 'es5'
tabWidth: 2
semi: false
singleQuote: true
printWidth: 88
quoteProps: "consistent"
quoteProps: 'consistent'
plugins:
- prettier-plugin-curly

724
package-lock.json generated
View file

@ -41,10 +41,368 @@
"mocha": "^10.2.0",
"optimist": "~0.4.0",
"prettier": "^2.8.8",
"prettier-plugin-curly": "^0.1.3",
"sinon": "^15.1.0",
"uglify-js": "~3.17.4"
}
},
"node_modules/@babel/code-frame": {
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
"integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==",
"dev": true,
"dependencies": {
"@babel/highlight": "^7.22.13",
"chalk": "^2.4.2"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/code-frame/node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"dependencies": {
"color-convert": "^1.9.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"dependencies": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"dependencies": {
"color-name": "1.1.3"
}
},
"node_modules/@babel/code-frame/node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"node_modules/@babel/code-frame/node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true,
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/@babel/code-frame/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/generator": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz",
"integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==",
"dev": true,
"dependencies": {
"@babel/types": "^7.23.0",
"@jridgewell/gen-mapping": "^0.3.2",
"@jridgewell/trace-mapping": "^0.3.17",
"jsesc": "^2.5.1"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-environment-visitor": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
"integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==",
"dev": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-function-name": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz",
"integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==",
"dev": true,
"dependencies": {
"@babel/template": "^7.22.15",
"@babel/types": "^7.23.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-hoist-variables": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz",
"integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==",
"dev": true,
"dependencies": {
"@babel/types": "^7.22.5"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-split-export-declaration": {
"version": "7.22.6",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz",
"integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==",
"dev": true,
"dependencies": {
"@babel/types": "^7.22.5"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-string-parser": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz",
"integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==",
"dev": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
"dev": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/highlight": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz",
"integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==",
"dev": true,
"dependencies": {
"@babel/helper-validator-identifier": "^7.22.20",
"chalk": "^2.4.2",
"js-tokens": "^4.0.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/highlight/node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"dependencies": {
"color-convert": "^1.9.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/highlight/node_modules/chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"dependencies": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/highlight/node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"dependencies": {
"color-name": "1.1.3"
}
},
"node_modules/@babel/highlight/node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"node_modules/@babel/highlight/node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true,
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/@babel/highlight/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/highlight/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/parser": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz",
"integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==",
"dev": true,
"bin": {
"parser": "bin/babel-parser.js"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@babel/template": {
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz",
"integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==",
"dev": true,
"dependencies": {
"@babel/code-frame": "^7.22.13",
"@babel/parser": "^7.22.15",
"@babel/types": "^7.22.15"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/traverse": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz",
"integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==",
"dev": true,
"dependencies": {
"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.0",
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-function-name": "^7.23.0",
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"debug": "^4.1.0",
"globals": "^11.1.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/types": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz",
"integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==",
"dev": true,
"dependencies": {
"@babel/helper-string-parser": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.20",
"to-fast-properties": "^2.0.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz",
"integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==",
"dev": true,
"dependencies": {
"@jridgewell/set-array": "^1.0.1",
"@jridgewell/sourcemap-codec": "^1.4.10",
"@jridgewell/trace-mapping": "^0.3.9"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/resolve-uri": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
"integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
"dev": true,
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/set-array": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz",
"integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==",
"dev": true,
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.4.15",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==",
"dev": true
},
"node_modules/@jridgewell/trace-mapping": {
"version": "0.3.19",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz",
"integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==",
"dev": true,
"dependencies": {
"@jridgewell/resolve-uri": "^3.1.0",
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@mapbox/sexagesimal": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mapbox/sexagesimal/-/sexagesimal-1.1.0.tgz",
@ -1021,6 +1379,15 @@
"node": ">= 6"
}
},
"node_modules/globals": {
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/gopd": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
@ -1310,6 +1677,12 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"node_modules/js-yaml": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
@ -1322,6 +1695,18 @@
"js-yaml": "bin/js-yaml.js"
}
},
"node_modules/jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true,
"bin": {
"jsesc": "bin/jsesc"
},
"engines": {
"node": ">=4"
}
},
"node_modules/jsonparse": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz",
@ -1995,6 +2380,22 @@
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/prettier-plugin-curly": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/prettier-plugin-curly/-/prettier-plugin-curly-0.1.3.tgz",
"integrity": "sha512-NYr2BPex/0fFwDbiZZr91kfgBko1tmaorLOrVAkT5rN91mIYYJRiWabRxWGFqzRSO7J0eoEcxakY9NWvJWAh4w==",
"dev": true,
"dependencies": {
"@babel/parser": "^7.22.5",
"@babel/traverse": "^7.22.5"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"prettier": "^2 || ^3"
}
},
"node_modules/process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
@ -2286,6 +2687,15 @@
"tiny-inflate": "^1.0.2"
}
},
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
"integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@ -2555,6 +2965,286 @@
}
},
"dependencies": {
"@babel/code-frame": {
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
"integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==",
"dev": true,
"requires": {
"@babel/highlight": "^7.22.13",
"chalk": "^2.4.2"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"@babel/generator": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz",
"integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==",
"dev": true,
"requires": {
"@babel/types": "^7.23.0",
"@jridgewell/gen-mapping": "^0.3.2",
"@jridgewell/trace-mapping": "^0.3.17",
"jsesc": "^2.5.1"
}
},
"@babel/helper-environment-visitor": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
"integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==",
"dev": true
},
"@babel/helper-function-name": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz",
"integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==",
"dev": true,
"requires": {
"@babel/template": "^7.22.15",
"@babel/types": "^7.23.0"
}
},
"@babel/helper-hoist-variables": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz",
"integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==",
"dev": true,
"requires": {
"@babel/types": "^7.22.5"
}
},
"@babel/helper-split-export-declaration": {
"version": "7.22.6",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz",
"integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==",
"dev": true,
"requires": {
"@babel/types": "^7.22.5"
}
},
"@babel/helper-string-parser": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz",
"integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==",
"dev": true
},
"@babel/helper-validator-identifier": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
"dev": true
},
"@babel/highlight": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz",
"integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.22.20",
"chalk": "^2.4.2",
"js-tokens": "^4.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"@babel/parser": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz",
"integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==",
"dev": true
},
"@babel/template": {
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz",
"integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.22.13",
"@babel/parser": "^7.22.15",
"@babel/types": "^7.22.15"
}
},
"@babel/traverse": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz",
"integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.0",
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-function-name": "^7.23.0",
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"debug": "^4.1.0",
"globals": "^11.1.0"
}
},
"@babel/types": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz",
"integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==",
"dev": true,
"requires": {
"@babel/helper-string-parser": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.20",
"to-fast-properties": "^2.0.0"
}
},
"@jridgewell/gen-mapping": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz",
"integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==",
"dev": true,
"requires": {
"@jridgewell/set-array": "^1.0.1",
"@jridgewell/sourcemap-codec": "^1.4.10",
"@jridgewell/trace-mapping": "^0.3.9"
}
},
"@jridgewell/resolve-uri": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
"integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
"dev": true
},
"@jridgewell/set-array": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz",
"integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==",
"dev": true
},
"@jridgewell/sourcemap-codec": {
"version": "1.4.15",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==",
"dev": true
},
"@jridgewell/trace-mapping": {
"version": "0.3.19",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz",
"integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==",
"dev": true,
"requires": {
"@jridgewell/resolve-uri": "^3.1.0",
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"@mapbox/sexagesimal": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mapbox/sexagesimal/-/sexagesimal-1.1.0.tgz",
@ -3296,6 +3986,12 @@
"is-glob": "^4.0.1"
}
},
"globals": {
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
"dev": true
},
"gopd": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
@ -3506,6 +4202,12 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"js-yaml": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
@ -3515,6 +4217,12 @@
"argparse": "^2.0.1"
}
},
"jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true
},
"jsonparse": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz",
@ -4042,6 +4750,16 @@
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
"dev": true
},
"prettier-plugin-curly": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/prettier-plugin-curly/-/prettier-plugin-curly-0.1.3.tgz",
"integrity": "sha512-NYr2BPex/0fFwDbiZZr91kfgBko1tmaorLOrVAkT5rN91mIYYJRiWabRxWGFqzRSO7J0eoEcxakY9NWvJWAh4w==",
"dev": true,
"requires": {
"@babel/parser": "^7.22.5",
"@babel/traverse": "^7.22.5"
}
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
@ -4269,6 +4987,12 @@
"tiny-inflate": "^1.0.2"
}
},
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
"integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
"dev": true
},
"to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",

View file

@ -12,6 +12,7 @@
"mocha": "^10.2.0",
"optimist": "~0.4.0",
"prettier": "^2.8.8",
"prettier-plugin-curly": "^0.1.3",
"sinon": "^15.1.0",
"uglify-js": "~3.17.4"
},

View file

@ -70,7 +70,9 @@ L.U.AutoComplete = L.Class.extend({
onKeyDown: function (e) {
switch (e.keyCode) {
case L.U.Keys.TAB:
if (this.CURRENT !== null) this.setChoice()
if (this.CURRENT !== null) {
this.setChoice()
}
L.DomEvent.stop(e)
break
case L.U.Keys.ENTER:
@ -164,8 +166,11 @@ L.U.AutoComplete = L.Class.extend({
this.clear()
return
}
if (`${val}` === `${this.CACHE}`) return
else this.CACHE = val
if (`${val}` === `${this.CACHE}`) {
return
} else {
this.CACHE = val
}
this._do_search(
val,
function (data) {
@ -227,8 +232,11 @@ L.U.AutoComplete = L.Class.extend({
highlight: function () {
this.forEach(this.RESULTS, (result, index) => {
if (index === this.CURRENT) L.DomUtil.addClass(result.el, 'on')
else L.DomUtil.removeClass(result.el, 'on')
if (index === this.CURRENT) {
L.DomUtil.addClass(result.el, 'on')
} else {
L.DomUtil.removeClass(result.el, 'on')
}
})
},
@ -260,7 +268,9 @@ L.U.AutoComplete = L.Class.extend({
L.U.AutoComplete.Ajax = L.U.AutoComplete.extend({
initialize: function (el, options) {
L.U.AutoComplete.prototype.initialize.call(this, el, options)
if (!this.el) return this
if (!this.el) {
return this
}
this.createInput()
this.createContainer()
this.selected_container = this.initSelectedContainer()

View file

@ -6,8 +6,9 @@ L.U.BaseAction = L.ToolbarAction.extend({
tooltip: this.options.tooltip,
}
L.ToolbarAction.prototype.initialize.call(this)
if (this.options.helpMenu && !this.map.helpMenuActions[this.options.className])
if (this.options.helpMenu && !this.map.helpMenuActions[this.options.className]) {
this.map.helpMenuActions[this.options.className] = this
}
},
})
@ -177,8 +178,11 @@ L.U.ToggleEditAction = L.U.BaseFeatureAction.extend({
},
onClick: function (e) {
if (this.feature._toggleEditing) this.feature._toggleEditing(e) // Path
else this.feature.edit(e) // Marker
if (this.feature._toggleEditing) {
this.feature._toggleEditing(e)
} else {
this.feature.edit(e)
} // Marker
},
})
@ -191,8 +195,9 @@ L.U.DeleteFeatureAction = L.U.BaseFeatureAction.extend({
},
postInit: function () {
if (!this.feature.isMulti())
if (!this.feature.isMulti()) {
this.options.toolbarIcon.className = 'umap-delete-one-of-one'
}
},
onClick: function (e) {
@ -275,7 +280,9 @@ L.U.ContinueLineAction = L.U.BaseVertexAction.extend({
// Leaflet.Toolbar doesn't allow twice same toolbar class…
L.U.SettingsToolbar = L.Toolbar.Control.extend({
addTo: function (map) {
if (map.options.editMode !== 'advanced') return
if (map.options.editMode !== 'advanced') {
return
}
L.Toolbar.Control.prototype.addTo.call(this, map)
},
})
@ -382,8 +389,11 @@ L.U.MoreControls = L.Control.extend({
const pos = this.getPosition(),
corner = this._map._controlCorners[pos],
className = 'umap-more-controls'
if (L.DomUtil.hasClass(corner, className)) L.DomUtil.removeClass(corner, className)
else L.DomUtil.addClass(corner, className)
if (L.DomUtil.hasClass(corner, className)) {
L.DomUtil.removeClass(corner, className)
} else {
L.DomUtil.addClass(corner, className)
}
},
})
@ -502,8 +512,12 @@ L.U.DataLayersControl = L.Control.extend({
},
onAdd: function (map) {
if (!this._container) this._initLayout(map)
if (map.options.datalayersControl === 'expanded') this.expand()
if (!this._container) {
this._initLayout(map)
}
if (map.options.datalayersControl === 'expanded') {
this.expand()
}
return this._container
},
@ -525,18 +539,21 @@ L.U.DataLayersControl = L.Control.extend({
},
collapse: function () {
if (this._map.options.datalayersControl === 'expanded') return
if (this._map.options.datalayersControl === 'expanded') {
return
}
L.DomUtil.removeClass(this._container, 'expanded')
},
addDataLayer: function (container, datalayer, draggable) {
const datalayerLi = L.DomUtil.create('li', '', container)
if (draggable)
if (draggable) {
L.DomUtil.element(
'i',
{ className: 'drag-handle', title: L._('Drag to reorder') },
datalayerLi
)
}
datalayer.renderToolbox(datalayerLi)
const title = L.DomUtil.add(
'span',
@ -557,7 +574,9 @@ L.U.DataLayersControl = L.Control.extend({
},
openPanel: function () {
if (!this.map.editEnabled) return
if (!this.map.editEnabled) {
return
}
const container = L.DomUtil.create('ul', 'umap-browse-datalayers')
this.map.eachDataLayerReverse(function (datalayer) {
this.addDataLayer(container, datalayer, true)
@ -569,11 +588,17 @@ L.U.DataLayersControl = L.Control.extend({
const layer = this.map.datalayers[e.src.dataset.id],
other = this.map.datalayers[e.dst.dataset.id],
minIndex = Math.min(e.initialIndex, e.finalIndex)
if (e.finalIndex === 0) layer.bringToTop()
else if (e.finalIndex > e.initialIndex) layer.insertBefore(other)
else layer.insertAfter(other)
if (e.finalIndex === 0) {
layer.bringToTop()
} else if (e.finalIndex > e.initialIndex) {
layer.insertBefore(other)
} else {
layer.insertAfter(other)
}
this.map.eachDataLayerReverse((datalayer) => {
if (datalayer.getRank() >= minIndex) datalayer.isDirty = true
if (datalayer.getRank() >= minIndex) {
datalayer.isDirty = true
}
})
this.map.indexDatalayers()
},
@ -615,16 +640,19 @@ L.U.DataLayer.include({
remove.title = L._('Delete layer')
if (this.isReadOnly()) {
L.DomUtil.addClass(container, 'readonly')
}
else {
} else {
L.DomEvent.on(edit, 'click', this.edit, this)
L.DomEvent.on(table, 'click', this.tableEdit, this)
L.DomEvent.on(
remove,
'click',
function () {
if (!this.isVisible()) return
if (!confirm(L._('Are you sure you want to delete this layer?'))) return
if (!this.isVisible()) {
return
}
if (!confirm(L._('Are you sure you want to delete this layer?'))) {
return
}
this._delete()
this.map.ui.closePanel()
},
@ -673,7 +701,9 @@ L.U.DataLayer.include({
L.U.DataLayer.addInitHook(function () {
this.on('hide', this.propagateHide)
this.on('show', this.propagateShow)
if (this.isVisible()) this.propagateShow()
if (this.isVisible()) {
this.propagateShow()
}
})
L.U.Map.include({
@ -761,7 +791,9 @@ L.U.Map.include({
const build = () => {
ul.innerHTML = ''
datalayer.eachFeature((feature) => {
if (filterValue && !feature.matchFilter(filterValue, filterKeys)) return
if (filterValue && !feature.matchFilter(filterValue, filterKeys)) {
return
}
ul.appendChild(addFeature(feature))
})
}
@ -808,7 +840,9 @@ L.U.Map.include({
keys.forEach((key) => {
knownValues[key] = []
if (!this.facets[key]) this.facets[key] = []
if (!this.facets[key]) {
this.facets[key] = []
}
})
this.eachBrowsableDataLayer((datalayer) => {
@ -826,11 +860,14 @@ L.U.Map.include({
let found = false
this.eachBrowsableDataLayer((datalayer) => {
datalayer.resetLayer(true)
if (datalayer.hasDataVisible()) found = true
if (datalayer.hasDataVisible()) {
found = true
}
})
// TODO: display a results counter in the panel instead.
if (!found)
if (!found) {
this.ui.alert({ content: L._('No results for these facets'), level: 'info' })
}
}
const fields = keys.map((current) => [
@ -996,10 +1033,11 @@ L.U.Map.include({
const status = this.permissions.getShareStatusDisplay()
name.textContent = this.getDisplayName()
// status is not set until map is saved once
if (status)
if (status) {
share_status.textContent = L._('Visibility: {status}', {
status: status,
})
}
}
update()
this.once('saved', L.bind(update, this))
@ -1127,8 +1165,11 @@ L.U.Map.include({
)
exportCaveat.id = 'export_caveat_text'
const toggleCaveat = () => {
if (typeInput.value === 'umap') exportCaveat.style.display = 'none'
else exportCaveat.style.display = 'inherit'
if (typeInput.value === 'umap') {
exportCaveat.style.display = 'none'
} else {
exportCaveat.style.display = 'inherit'
}
}
L.DomEvent.on(typeInput, 'change', toggleCaveat)
for (const key in this.EXPORT_TYPES) {
@ -1136,15 +1177,20 @@ L.U.Map.include({
option = L.DomUtil.create('option', '', typeInput)
option.value = key
option.textContent = this.EXPORT_TYPES[key].name || key
if (this.EXPORT_TYPES[key].selected) option.selected = true
if (this.EXPORT_TYPES[key].selected) {
option.selected = true
}
}
}
toggleCaveat()
const download = L.DomUtil.create('a', 'button', container)
download.textContent = L._('Download data')
L.DomEvent.on(download, 'click', () => {
if (typeInput.value === 'umap') this.fullDownload()
else this.download(typeInput.value)
if (typeInput.value === 'umap') {
this.fullDownload()
} else {
this.download(typeInput.value)
}
})
this.ui.openPanel({ data: { html: container } })
},
@ -1215,8 +1261,9 @@ L.U.TileLayerControl = L.Control.extend({
if (
window.location.protocol === 'https:' &&
tilelayer.options.url_template.indexOf('http:') === 0
)
) {
return
}
this.addTileLayerElement(tilelayer, options)
}, this)
this.map.ui.openPanel({
@ -1238,7 +1285,9 @@ L.U.TileLayerControl = L.Control.extend({
'click',
function () {
this.map.selectTileLayer(tilelayer)
if (options && options.callback) options.callback(tilelayer)
if (options && options.callback) {
options.callback(tilelayer)
}
},
this
)
@ -1309,7 +1358,9 @@ L.U.Search = L.PhotonSearch.extend({
initialize: function (map, input, options) {
L.PhotonSearch.prototype.initialize.call(this, map, input, options)
this.options.url = map.options.urls.search
if (map.options.maxBounds) this.options.bbox = map.options.maxBounds.toBBoxString()
if (map.options.maxBounds) {
this.options.bbox = map.options.maxBounds.toBBoxString()
}
},
onBlur: function (e) {
@ -1379,7 +1430,9 @@ L.U.SearchControl = L.Control.extend({
limit: 10,
noResultLabel: L._('No results'),
}
if (map.options.photonUrl) options.url = map.options.photonUrl
if (map.options.photonUrl) {
options.url = map.options.photonUrl
}
const container = L.DomUtil.create('div', '')
const title = L.DomUtil.create('h3', '', container)
@ -1537,13 +1590,18 @@ L.U.Editable = L.Editable.extend({
this.on('editable:drawing:end', this.closeTooltip)
// Layer for items added by users
this.on('editable:drawing:cancel', (e) => {
if (e.layer._latlngs && e.layer._latlngs.length < e.layer.editor.MIN_VERTEX)
if (e.layer._latlngs && e.layer._latlngs.length < e.layer.editor.MIN_VERTEX) {
e.layer.del()
if (e.layer instanceof L.U.Marker) e.layer.del()
}
if (e.layer instanceof L.U.Marker) {
e.layer.del()
}
})
this.on('editable:drawing:commit', function (e) {
e.layer.isDirty = true
if (this.map.editedFeature !== e.layer) e.layer.edit(e)
if (this.map.editedFeature !== e.layer) {
e.layer.edit(e)
}
})
this.on('editable:editing', (e) => {
const layer = e.layer
@ -1555,11 +1613,14 @@ L.U.Editable = L.Editable.extend({
})
this.on('editable:vertex:ctrlclick', (e) => {
const index = e.vertex.getIndex()
if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue))
if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue)) {
e.vertex.continue()
}
})
this.on('editable:vertex:altclick', (e) => {
if (e.vertex.editor.vertexCanBeDeleted(e.vertex)) e.vertex.delete()
if (e.vertex.editor.vertexCanBeDeleted(e.vertex)) {
e.vertex.delete()
}
})
this.on('editable:vertex:rawclick', this.onVertexRawClick)
},
@ -1576,7 +1637,7 @@ L.U.Editable = L.Editable.extend({
return new L.U.Marker(this.map, latlng, this._getDefaultProperties())
},
_getDefaultProperties: function() {
_getDefaultProperties: function () {
const result = {}
if (this.map.options.featuresHaveOwner && this.map.options.hasOwnProperty('user')) {
result.geojson = { properties: { owner: this.map.options.user.id } }

View file

@ -13,7 +13,9 @@ L.Util.queryString = (name, fallback) => {
qa = {}
for (const i in qs) {
const key = qs[i].split('=')
if (!key) continue
if (!key) {
continue
}
qa[decode(key[0])] = key[1] ? decode(key[1]) : 1
}
return qa[name] || fallback
@ -26,19 +28,27 @@ L.Util.booleanFromQueryString = (name) => {
L.Util.setFromQueryString = (options, name) => {
const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value
if (typeof value !== 'undefined') {
options[name] = value
}
}
L.Util.setBooleanFromQueryString = (options, name) => {
const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true'
if (typeof value !== 'undefined') {
options[name] = value == '1' || value == 'true'
}
}
L.Util.setNullableBooleanFromQueryString = (options, name) => {
let value = L.Util.queryString(name)
if (typeof value !== 'undefined') {
if (value === 'null') value = null
else if (value === '0' || value === 'false') value = false
else value = true
if (value === 'null') {
value = null
} else if (value === '0' || value === 'false') {
value = false
} else {
value = true
}
options[name] = value
}
}
@ -74,7 +84,9 @@ L.Util.escapeHTML = (s) => {
return s
}
L.Util.toHTML = (r, options) => {
if (!r) return ''
if (!r) {
return ''
}
const target = (options && options.target) || 'blank'
let ii
@ -94,8 +106,9 @@ L.Util.toHTML = (r, options) => {
// unordered lists
r = r.replace(/^\*\* (.*)/gm, '<ul><ul><li>$1</li></ul></ul>')
r = r.replace(/^\* (.*)/gm, '<ul><li>$1</li></ul>')
for (ii = 0; ii < 3; ii++)
for (ii = 0; ii < 3; ii++) {
r = r.replace(new RegExp(`</ul>${newline}<ul>`, 'g'), newline)
}
// links
r = r.replace(/(\[\[http)/g, '[[h_t_t_p') // Escape for avoiding clash between [[http://xxx]] and http://xxx
@ -129,13 +142,18 @@ L.Util.toHTML = (r, options) => {
// images
r = r.replace(/{{([^\]|]*?)}}/g, '<img src="$1">')
r = r.replace(/{{([^|]*?)\|(\d*?)(px)?}}/g, '<img src="$1" style="width:$2px;min-width:$2px;">')
r = r.replace(
/{{([^|]*?)\|(\d*?)(px)?}}/g,
'<img src="$1" style="width:$2px;min-width:$2px;">'
)
//Unescape http
r = r.replace(/(h_t_t_p)/g, 'http')
// Preserver line breaks
if (newline) r = r.replace(new RegExp(`${newline}(?=[^]+)`, 'g'), `<br>${newline}`)
if (newline) {
r = r.replace(new RegExp(`${newline}(?=[^]+)`, 'g'), `<br>${newline}`)
}
r = L.Util.escapeHTML(r)
@ -151,13 +169,21 @@ L.Util.detectFileType = (f) => {
if (f.type === 'application/vnd.google-earth.kml+xml' || ext('.kml')) {
return 'kml'
}
if (ext('.gpx')) return 'gpx'
if (ext('.geojson') || ext('.json')) return 'geojson'
if (ext('.gpx')) {
return 'gpx'
}
if (ext('.geojson') || ext('.json')) {
return 'geojson'
}
if (f.type === 'text/csv' || ext('.csv') || ext('.tsv') || ext('.dsv')) {
return 'csv'
}
if (ext('.xml') || ext('.osm')) return 'osm'
if (ext('.umap')) return 'umap'
if (ext('.xml') || ext('.osm')) {
return 'osm'
}
if (ext('.umap')) {
return 'umap'
}
}
L.Util.usableOption = (options, option) =>
@ -168,7 +194,9 @@ L.Util.greedyTemplate = (str, data, ignore) => {
let value = data
for (let i = 0; i < path.length; i++) {
value = value[path[i]]
if (value === undefined) break
if (value === undefined) {
break
}
}
return value
}
@ -184,14 +212,21 @@ L.Util.greedyTemplate = (str, data, ignore) => {
}
for (let i = 0; i < vars.length; i++) {
path = vars[i]
if (path.startsWith('"') && path.endsWith('"'))
value = path.substring(1, path.length - 1) // static default value.
else value = getValue(data, path.split('.'))
if (value !== undefined) break
if (path.startsWith('"') && path.endsWith('"')) {
value = path.substring(1, path.length - 1)
} else {
value = getValue(data, path.split('.'))
}
if (value !== undefined) {
break
}
}
if (value === undefined) {
if (ignore) value = str
else value = ''
if (ignore) {
value = str
} else {
value = ''
}
}
return value
}
@ -224,7 +259,9 @@ L.Util.sortFeatures = (features, sortKey) => {
numeric: true,
})
}
if (score === 0 && sortKeys[i + 1]) return sort(a, b, i + 1)
if (score === 0 && sortKeys[i + 1]) {
return sort(a, b, i + 1)
}
return score * reverse
}
@ -239,7 +276,9 @@ L.Util.sortFeatures = (features, sortKey) => {
}
L.Util.flattenCoordinates = (coords) => {
while (coords[0] && typeof coords[0][0] !== 'number') coords = coords[0]
while (coords[0] && typeof coords[0][0] !== 'number') {
coords = coords[0]
}
return coords
}
@ -258,32 +297,31 @@ L.Util.hasVar = (value) => {
}
L.Util.copyToClipboard = function (textToCopy) {
// https://stackoverflow.com/a/65996386
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(textToCopy)
} else {
// Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea')
textArea.value = textToCopy
// https://stackoverflow.com/a/65996386
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(textToCopy)
} else {
// Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea')
textArea.value = textToCopy
// Move textarea out of the viewport so it's not visible
textArea.style.position = 'absolute'
textArea.style.left = '-999999px'
// Move textarea out of the viewport so it's not visible
textArea.style.position = 'absolute'
textArea.style.left = '-999999px'
document.body.prepend(textArea)
textArea.select()
document.body.prepend(textArea)
textArea.select()
try {
document.execCommand('copy')
} catch (error) {
console.error(error)
} finally {
textArea.remove()
}
}
try {
document.execCommand('copy')
} catch (error) {
console.error(error)
} finally {
textArea.remove()
}
}
}
L.DomUtil.add = (tagName, className, container, content) => {
const el = L.DomUtil.create(tagName, className, container)
@ -307,7 +345,9 @@ L.DomUtil.createFieldset = (container, legend, options) => {
L.DomUtil.removeClass(fieldset, 'on')
} else {
L.DomUtil.addClass(fieldset, 'on')
if (options.callback) options.callback.call(options.context || this)
if (options.callback) {
options.callback.call(options.context || this)
}
}
})
return fieldsEl
@ -323,8 +363,11 @@ L.DomUtil.createButton = (className, container, content, callback, context) => {
}
L.DomUtil.classIf = (el, className, bool) => {
if (bool) L.DomUtil.addClass(el, className)
else L.DomUtil.removeClass(el, className)
if (bool) {
L.DomUtil.addClass(el, className)
} else {
L.DomUtil.removeClass(el, className)
}
}
L.DomUtil.element = (what, attrs, parent) => {
@ -475,7 +518,7 @@ L.U.Help = L.Class.extend({
link: function (container, entries) {
const helpButton = this.button(container, entries, 'umap-help-link')
helpButton.textContent = L._("Help")
helpButton.textContent = L._('Help')
return helpButton
},
@ -635,7 +678,9 @@ L.U.Orderable = L.Evented.extend({
this.src = null
this.dst = null
this.els = this.parent.querySelectorAll(this.options.selector)
for (let i = 0; i < this.els.length; i++) this.makeDraggable(this.els[i])
for (let i = 0; i < this.els.length; i++) {
this.makeDraggable(this.els[i])
}
},
makeDraggable: function (node) {
@ -654,7 +699,9 @@ L.U.Orderable = L.Evented.extend({
findTarget: function (node) {
while (node) {
if (this.nodeIndex(node) !== -1) return node
if (this.nodeIndex(node) !== -1) {
return node
}
node = node.parentNode
}
},
@ -670,7 +717,9 @@ L.U.Orderable = L.Evented.extend({
},
onDragOver: function (e) {
if (e.preventDefault) e.preventDefault() // Necessary. Allows us to drop.
if (e.preventDefault) {
e.preventDefault()
} // Necessary. Allows us to drop.
e.dataTransfer.dropEffect = 'move'
return false
},
@ -678,12 +727,17 @@ L.U.Orderable = L.Evented.extend({
onDragEnter: function (e) {
// e.target is the current hover target.
const dst = this.findTarget(e.target)
if (!dst || dst === this.src) return
if (!dst || dst === this.src) {
return
}
this.dst = dst
const targetIndex = this.nodeIndex(this.dst),
srcIndex = this.nodeIndex(this.src)
if (targetIndex > srcIndex) this.parent.insertBefore(this.dst, this.src)
else this.parent.insertBefore(this.src, this.dst)
if (targetIndex > srcIndex) {
this.parent.insertBefore(this.dst, this.src)
} else {
this.parent.insertBefore(this.src, this.dst)
}
},
onDragLeave: function (e) {
@ -692,8 +746,12 @@ L.U.Orderable = L.Evented.extend({
onDrop: function (e) {
// e.target is current target element.
if (e.stopPropagation) e.stopPropagation() // Stops the browser from redirecting.
if (!this.dst) return
if (e.stopPropagation) {
e.stopPropagation()
} // Stops the browser from redirecting.
if (!this.dst) {
return
}
this.fire('drop', {
src: this.src,
initialIndex: this.initialIndex,

View file

@ -15,7 +15,9 @@ L.U.DataLayerPermissions = L.Class.extend({
},
set: function (status) {
isDirty = status
if (status) self.datalayer.isDirty = status
if (status) {
self.datalayer.isDirty = status
}
},
})
} catch (e) {
@ -38,7 +40,9 @@ L.U.DataLayerPermissions = L.Class.extend({
},
],
],
builder = new L.U.FormBuilder(this, fields, {className: 'umap-form datalayer-permissions'}),
builder = new L.U.FormBuilder(this, fields, {
className: 'umap-form datalayer-permissions',
}),
form = builder.build()
container.appendChild(form)
},
@ -50,7 +54,9 @@ L.U.DataLayerPermissions = L.Class.extend({
})
},
save: function () {
if (!this.isDirty) return this.datalayer.map.continueSaving()
if (!this.isDirty) {
return this.datalayer.map.continueSaving()
}
const formData = new FormData()
formData.append('edit_status', this.options.edit_status)
this.datalayer.map.post(this.getUrl(), {

View file

@ -49,14 +49,17 @@ L.U.FeatureMixin = {
getPermalink: function () {
const slug = this.getSlug()
if (slug)
if (slug) {
return `${L.Util.getBaseUrl()}?${L.Util.buildQueryString({ feature: slug })}${
window.location.hash
}`
}
},
view: function (e) {
if (this.map.editEnabled) return
if (this.map.editEnabled) {
return
}
const outlink = this.getOption('outlink'),
target = this.getOption('outlinkTarget')
if (outlink) {
@ -73,19 +76,25 @@ L.U.FeatureMixin = {
return
}
// TODO deal with an event instead?
if (this.map.slideshow) this.map.slideshow.current = this
if (this.map.slideshow) {
this.map.slideshow.current = this
}
this.map.currentFeature = this
this.attachPopup()
this.openPopup((e && e.latlng) || this.getCenter())
},
openPopup: function () {
if (this.map.editEnabled) return
if (this.map.editEnabled) {
return
}
this.parentClass.prototype.openPopup.apply(this, arguments)
},
edit: function (e) {
if (!this.map.editEnabled || this.isReadOnly()) return
if (!this.map.editEnabled || this.isReadOnly()) {
return
}
const container = L.DomUtil.create('div', 'umap-feature-container')
L.DomUtil.add(
'h3',
@ -126,7 +135,9 @@ L.U.FeatureMixin = {
this.getAdvancedEditActions(advancedActions)
this.map.ui.openPanel({ data: { html: container }, className: 'dark' })
this.map.editedFeature = this
if (!this.isOnScreen()) this.zoomTo(e)
if (!this.isOnScreen()) {
this.zoomTo(e)
}
},
getAdvancedEditActions: function (container) {
@ -138,7 +149,9 @@ L.U.FeatureMixin = {
'click',
function (e) {
L.DomEvent.stop(e)
if (this.confirmDelete()) this.map.ui.closePanel()
if (this.confirmDelete()) {
this.map.ui.closePanel()
}
},
this
)
@ -190,18 +203,25 @@ L.U.FeatureMixin = {
endEdit: function () {},
getDisplayName: function (fallback) {
if (fallback === undefined) fallback = this.datalayer.options.name
if (fallback === undefined) {
fallback = this.datalayer.options.name
}
const key = this.getOption('labelKey') || 'name'
// Variables mode.
if (L.Util.hasVar(key)) return L.Util.greedyTemplate(key, this.extendedProperties())
if (L.Util.hasVar(key)) {
return L.Util.greedyTemplate(key, this.extendedProperties())
}
// Simple mode.
return this.properties[key] || this.properties.title || fallback
},
hasPopupFooter: function () {
if (L.Browser.ielt9) return false
if (this.datalayer.isRemoteLayer() && this.datalayer.options.remoteData.dynamic)
if (L.Browser.ielt9) {
return false
}
if (this.datalayer.isRemoteLayer() && this.datalayer.options.remoteData.dynamic) {
return false
}
return this.map.options.displayPopupFooter
},
@ -295,7 +315,9 @@ L.U.FeatureMixin = {
// There is a variable inside.
if (L.Util.hasVar(value)) {
value = L.Util.greedyTemplate(value, this.properties, true)
if (L.Util.hasVar(value)) value = this.map.getDefaultOption(option)
if (L.Util.hasVar(value)) {
value = this.map.getDefaultOption(option)
}
}
return value
},
@ -309,7 +331,9 @@ L.U.FeatureMixin = {
const latlng = e.latlng || this.getCenter()
this.map.setView(latlng, this.getBestZoom() || this.map.getZoom())
}
if (e.callback) e.callback.call(this)
if (e.callback) {
e.callback.call(this)
}
},
getBestZoom: function () {
@ -356,7 +380,9 @@ L.U.FeatureMixin = {
},
_onClick: function (e) {
if (this.map.measureTools && this.map.measureTools.enabled()) return
if (this.map.measureTools && this.map.measureTools.enabled()) {
return
}
this._popupHandlersAdded = true // Prevent leaflet from managing event
if (!this.map.editEnabled) {
this.view(e)
@ -365,8 +391,11 @@ L.U.FeatureMixin = {
if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
this.datalayer.edit(e)
} else {
if (this._toggleEditing) this._toggleEditing(e)
else this.edit(e)
if (this._toggleEditing) {
this._toggleEditing(e)
} else {
this.edit(e)
}
}
} else {
new L.Toolbar.Popup(e.latlng, {
@ -405,13 +434,14 @@ L.U.FeatureMixin = {
getContextMenuItems: function (e) {
const permalink = this.getPermalink()
let items = []
if (permalink)
if (permalink) {
items.push({
text: L._('Permalink'),
callback: function () {
window.open(permalink)
},
})
}
if (this.map.editEnabled && !this.isReadOnly()) {
items = items.concat(this.getContextMenuEditItems(e))
}
@ -459,7 +489,9 @@ L.U.FeatureMixin = {
},
resetTooltip: function () {
if (!this.hasGeom()) return
if (!this.hasGeom()) {
return
}
const displayName = this.getDisplayName(null)
let showLabel = this.getOption('showLabel')
const oldLabelHover = this.getOption('labelHover')
@ -469,18 +501,22 @@ L.U.FeatureMixin = {
interactive: this.getOption('labelInteractive'),
}
if (oldLabelHover && showLabel) showLabel = null // Retrocompat.
if (oldLabelHover && showLabel) {
showLabel = null
} // Retrocompat.
options.permanent = showLabel === true
this.unbindTooltip()
if ((showLabel === true || showLabel === null) && displayName)
if ((showLabel === true || showLabel === null) && displayName) {
this.bindTooltip(L.Util.escapeHTML(displayName), options)
}
},
matchFilter: function (filter, keys) {
filter = filter.toLowerCase()
for (let i = 0; i < keys.length; i++) {
if ((this.properties[keys[i]] || '').toLowerCase().indexOf(filter) !== -1)
if ((this.properties[keys[i]] || '').toLowerCase().indexOf(filter) !== -1) {
return true
}
}
return false
},
@ -490,7 +526,9 @@ L.U.FeatureMixin = {
for (const [property, expected] of Object.entries(facets)) {
if (expected.length) {
let value = this.properties[property]
if (!value || !expected.includes(value)) return false
if (!value || !expected.includes(value)) {
return false
}
}
}
return true
@ -521,8 +559,12 @@ L.U.FeatureMixin = {
extendedProperties: function () {
// Include context properties
properties = this.map.getGeoContext()
if (L.locale) properties.locale = L.locale
if (L.lang) properties.lang = L.lang
if (L.locale) {
properties.locale = L.locale
}
if (L.lang) {
properties.lang = L.lang
}
properties.rank = this.getRank() + 1
if (this.hasGeom()) {
center = this.getCenter()
@ -559,7 +601,9 @@ L.U.Marker = L.Marker.extend({
},
this
)
if (!this.isReadOnly()) this.on('mouseover', this._enableDragging)
if (!this.isReadOnly()) {
this.on('mouseover', this._enableDragging)
}
this.on('mouseout', this._onMouseOut)
this._popupHandlersAdded = true // prevent Leaflet from binding event on bindPopup
},
@ -582,7 +626,9 @@ L.U.Marker = L.Marker.extend({
_enableDragging: function () {
// TODO: start dragging after 1 second on mouse down
if (this.map.editEnabled) {
if (!this.editEnabled()) this.enableEdit()
if (!this.editEnabled()) {
this.enableEdit()
}
// Enabling dragging on the marker override the Draggable._OnDown
// event, which, as it stopPropagation, refrain the call of
// _onDown with map-pane element, which is responsible to
@ -594,7 +640,9 @@ L.U.Marker = L.Marker.extend({
_disableDragging: function () {
if (this.map.editEnabled) {
if (this.editor && this.editor.drawing) return // when creating a new marker, the mouse can trigger the mouseover/mouseout event
if (this.editor && this.editor.drawing) {
return
} // when creating a new marker, the mouse can trigger the mouseover/mouseout event
// do not listen to them
this.disableEdit()
}
@ -633,7 +681,9 @@ L.U.Marker = L.Marker.extend({
},
_getIconUrl: function (name) {
if (typeof name === 'undefined') name = 'icon'
if (typeof name === 'undefined') {
name = 'icon'
}
return this.getOption(`${name}Url`)
},
@ -724,7 +774,9 @@ L.U.PathMixin = {
edit: function (e) {
if (this.map.editEnabled) {
if (!this.editEnabled()) this.enableEdit()
if (!this.editEnabled()) {
this.enableEdit()
}
L.U.FeatureMixin.edit.call(this, e)
}
},
@ -778,8 +830,11 @@ L.U.PathMixin = {
option = this.styleOptions[idx]
options[option] = this.getDynamicOption(option)
}
if (options.interactive) this.options.pointerEvents = 'visiblePainted'
else this.options.pointerEvents = 'stroke'
if (options.interactive) {
this.options.pointerEvents = 'visiblePainted'
} else {
this.options.pointerEvents = 'stroke'
}
this.parentClass.prototype.setStyle.call(this, options)
},
@ -796,14 +851,18 @@ L.U.PathMixin = {
// this.map.on('showmeasure', this.showMeasureTooltip, this);
// this.map.on('hidemeasure', this.removeTooltip, this);
this.parentClass.prototype.onAdd.call(this, map)
if (this.editing && this.editing.enabled()) this.editing.addHooks()
if (this.editing && this.editing.enabled()) {
this.editing.addHooks()
}
this.resetTooltip()
},
onRemove: function (map) {
// this.map.off('showmeasure', this.showMeasureTooltip, this);
// this.map.off('hidemeasure', this.removeTooltip, this);
if (this.editing && this.editing.enabled()) this.editing.removeHooks()
if (this.editing && this.editing.enabled()) {
this.editing.removeHooks()
}
L.U.FeatureMixin.onRemove.call(this, map)
},
@ -832,22 +891,32 @@ L.U.PathMixin = {
},
_onDrag: function () {
if (this._tooltip) this._tooltip.setLatLng(this.getCenter())
if (this._tooltip) {
this._tooltip.setLatLng(this.getCenter())
}
},
transferShape: function (at, to) {
const shape = this.enableEdit().deleteShapeAt(at)
this.disableEdit()
if (!shape) return
if (!shape) {
return
}
to.enableEdit().appendShape(shape)
if (!this._latlngs.length || !this._latlngs[0].length) this.del()
if (!this._latlngs.length || !this._latlngs[0].length) {
this.del()
}
},
isolateShape: function (at) {
if (!this.isMulti()) return
if (!this.isMulti()) {
return
}
const shape = this.enableEdit().deleteShapeAt(at)
this.disableEdit()
if (!shape) return
if (!shape) {
return
}
const properties = this.cloneProperties()
const other = new (this instanceof L.U.Polyline ? L.U.Polyline : L.U.Polygon)(
this.map,
@ -1055,14 +1124,20 @@ L.U.Polyline = L.Polyline.extend({
},
mergeShapes: function () {
if (!this.isMulti()) return
if (!this.isMulti()) {
return
}
const latlngs = this.getLatLngs()
if (!latlngs.length) return
if (!latlngs.length) {
return
}
while (latlngs.length > 1) {
latlngs.splice(0, 2, this._mergeShapes(latlngs[1], latlngs[0]))
}
this.setLatLngs(latlngs[0])
if (!this.editEnabled()) this.edit()
if (!this.editEnabled()) {
this.edit()
}
this.editor.reset()
this.isDirty = true
},
@ -1074,9 +1149,11 @@ L.U.Polyline = L.Polyline.extend({
getVertexActions: function (e) {
const actions = L.U.FeatureMixin.getVertexActions.call(this, e),
index = e.vertex.getIndex()
if (index === 0 || index === e.vertex.getLastIndex())
if (index === 0 || index === e.vertex.getLastIndex()) {
actions.push(L.U.ContinueLineAction)
else actions.push(L.U.SplitLineAction)
} else {
actions.push(L.U.SplitLineAction)
}
return actions
},
})

View file

@ -16,22 +16,30 @@ L.U.Icon = L.DivIcon.extend({
_getIconUrl: function (name) {
let url
if (this.feature && this.feature._getIconUrl(name))
if (this.feature && this.feature._getIconUrl(name)) {
url = this.feature._getIconUrl(name)
else url = this.options[`${name}Url`]
} else {
url = this.options[`${name}Url`]
}
return this.formatUrl(url, this.feature)
},
_getColor: function () {
let color
if (this.feature) color = this.feature.getDynamicOption('color')
else if (this.options.color) color = this.options.color
else color = this.map.getDefaultOption('color')
if (this.feature) {
color = this.feature.getDynamicOption('color')
} else if (this.options.color) {
color = this.options.color
} else {
color = this.map.getDefaultOption('color')
}
return color
},
_getOpacity: function () {
if (this.feature) return this.feature.getOption('iconOpacity')
if (this.feature) {
return this.feature.getOption('iconOpacity')
}
return this.map.getDefaultOption('iconOpacity')
},

View file

@ -67,11 +67,15 @@ L.U.Map.include({
initialize: function (el, geojson) {
// Locale name (pt_PT, en_US…)
// To be used for Django localization
if (geojson.properties.locale) L.setLocale(geojson.properties.locale)
if (geojson.properties.locale) {
L.setLocale(geojson.properties.locale)
}
// Language code (pt-pt, en-us…)
// To be used in javascript APIs
if (geojson.properties.lang) L.lang = geojson.properties.lang
if (geojson.properties.lang) {
L.lang = geojson.properties.lang
}
// Don't let default autocreation of controls
const zoomControl =
@ -89,7 +93,9 @@ L.U.Map.include({
L.Map.prototype.initialize.call(this, el, geojson.properties)
// After calling parent initialize, as we are doing initCenter our-selves
if (geojson.geometry) this.options.center = this.latLng(geojson.geometry)
if (geojson.geometry) {
this.options.center = this.latLng(geojson.geometry)
}
this.ui = new L.U.UI(this._container)
this.xhr = new L.U.Xhr(this.ui)
@ -121,10 +127,13 @@ L.U.Map.include({
'onLoadPanel',
this.options.onLoadPanel
)
if (this.datalayersOnLoad)
if (this.datalayersOnLoad) {
this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',')
}
if (L.Browser.ielt9) this.options.editMode = 'disabled' // TODO include ie9
if (L.Browser.ielt9) {
this.options.editMode = 'disabled'
} // TODO include ie9
let editedFeature = null
const self = this
@ -150,10 +159,12 @@ L.U.Map.include({
this.options.slideshow &&
this.options.slideshow.delay &&
this.options.slideshow.active === undefined
)
) {
this.options.slideshow.active = true
if (this.options.advancedFilterKey)
}
if (this.options.advancedFilterKey) {
this.options.facetKey = this.options.advancedFilterKey
}
// Global storage for retrieving datalayers and features
this.datalayers = {}
@ -162,7 +173,9 @@ L.U.Map.include({
this.features_index = {}
this.facets = {}
if (this.options.hash) this.addHash()
if (this.options.hash) {
this.addHash()
}
this.initTileLayers(this.options.tilelayers)
// Needs tilelayer to exist for minimap
this.initControls()
@ -211,7 +224,9 @@ L.U.Map.include({
this.on(
'baselayerchange',
function (e) {
if (this._controls.miniMap) this._controls.miniMap.onMainMapBaseLayerChange(e)
if (this._controls.miniMap) {
this._controls.miniMap.onMainMapBaseLayerChange(e)
}
},
this
)
@ -252,20 +267,30 @@ L.U.Map.include({
}
this.initShortcuts()
this.onceDatalayersLoaded(function () {
if (L.Util.queryString('share')) this.renderShareBox()
else if (this.options.onLoadPanel === 'databrowser') this.openBrowser()
else if (this.options.onLoadPanel === 'caption') this.displayCaption()
else if (
if (L.Util.queryString('share')) {
this.renderShareBox()
} else if (this.options.onLoadPanel === 'databrowser') {
this.openBrowser()
} else if (this.options.onLoadPanel === 'caption') {
this.displayCaption()
} else if (
this.options.onLoadPanel === 'facet' ||
this.options.onLoadPanel === 'datafilters'
)
) {
this.openFacet()
}
})
this.onceDataLoaded(function () {
const slug = L.Util.queryString('feature')
if (slug && this.features_index[slug]) this.features_index[slug].view()
if (L.Util.queryString('edit')) this.enableEdit()
if (L.Util.queryString('download')) this.download()
if (slug && this.features_index[slug]) {
this.features_index[slug].view()
}
if (L.Util.queryString('edit')) {
this.enableEdit()
}
if (L.Util.queryString('download')) {
this.download()
}
})
window.onbeforeunload = () => this.isDirty || null
@ -330,8 +355,11 @@ L.U.Map.include({
this._controls.more = new L.U.MoreControls()
this._controls.scale = L.control.scale()
this._controls.permanentCredit = new L.U.PermanentCreditsControl(this)
if (this.options.scrollWheelZoom) this.scrollWheelZoom.enable()
else this.scrollWheelZoom.disable()
if (this.options.scrollWheelZoom) {
this.scrollWheelZoom.enable()
} else {
this.scrollWheelZoom.disable()
}
this.renderControls()
},
@ -350,7 +378,9 @@ L.U.Map.include({
for (const i in this._controls) {
this.removeControl(this._controls[i])
}
if (this.options.noControl) return
if (this.options.noControl) {
return
}
this._controls.attribution = new L.U.AttributionControl().addTo(this)
if (this.options.miniMap && !this.options.noControl) {
@ -367,16 +397,26 @@ L.U.Map.include({
for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
name = this.HIDDABLE_CONTROLS[i]
status = this.options[`${name}Control`]
if (status === false) continue
if (status === false) {
continue
}
control = this._controls[name]
control.addTo(this)
if (status === undefined || status === null)
if (status === undefined || status === null) {
L.DomUtil.addClass(control._container, 'display-on-more')
else L.DomUtil.removeClass(control._container, 'display-on-more')
} else {
L.DomUtil.removeClass(control._container, 'display-on-more')
}
}
if (this.options.permanentCredit) {
this._controls.permanentCredit.addTo(this)
}
if (this.options.moreControl) {
this._controls.more.addTo(this)
}
if (this.options.scaleControl) {
this._controls.scale.addTo(this)
}
if (this.options.permanentCredit) this._controls.permanentCredit.addTo(this)
if (this.options.moreControl) this._controls.more.addTo(this)
if (this.options.scaleControl) this._controls.scale.addTo(this)
},
initDatalayers: function () {
@ -396,7 +436,9 @@ L.U.Map.include({
}
const decrementToLoad = () => {
toload--
if (toload === 0) loaded()
if (toload === 0) {
loaded()
}
}
const dataLoaded = () => {
this.dataLoaded = true
@ -404,7 +446,9 @@ L.U.Map.include({
}
const decrementDataToLoad = () => {
dataToload--
if (dataToload === 0) dataLoaded()
if (dataToload === 0) {
dataLoaded()
}
}
this.eachDataLayer(function (datalayer) {
if (force && !datalayer.hasDataLoaded()) {
@ -434,7 +478,9 @@ L.U.Map.include({
this.datalayers_index = []
for (let i = 0; i < panes.children.length; i++) {
pane = panes.children[i]
if (!pane.dataset || !pane.dataset.id) continue
if (!pane.dataset || !pane.dataset.id) {
continue
}
this.datalayers_index.push(this.datalayers[pane.dataset.id])
}
this.updateDatalayersControl()
@ -467,7 +513,9 @@ L.U.Map.include({
},
updateDatalayersControl: function () {
if (this._controls.datalayers) this._controls.datalayers.update()
if (this._controls.datalayers) {
this._controls.datalayers.update()
}
},
backupOptions: function () {
@ -493,11 +541,16 @@ L.U.Map.include({
L.DomEvent.stop(e)
this.search()
} else if (e.keyCode === L.U.Keys.ESC) {
if (this.help.visible()) this.help.hide()
else this.ui.closePanel()
if (this.help.visible()) {
this.help.hide()
} else {
this.ui.closePanel()
}
}
if (!this.hasEditMode()) return
if (!this.hasEditMode()) {
return
}
/* Edit mode only shortcuts */
if (key === L.U.Keys.E && modifierKey && !this.editEnabled) {
@ -544,8 +597,12 @@ L.U.Map.include({
this.help.show('edit')
}
if (e.keyCode === L.U.Keys.ESC) {
if (this.editEnabled) this.editTools.stopDrawing()
if (this.measureTools.enabled()) this.measureTools.stopDrawing()
if (this.editEnabled) {
this.editTools.stopDrawing()
}
if (this.measureTools.enabled()) {
this.measureTools.stopDrawing()
}
}
}
L.DomEvent.addListener(document, 'keydown', globalShortcuts, this)
@ -635,11 +692,15 @@ L.U.Map.include({
},
setOverlay: function () {
if (!this.options.overlay || !this.options.overlay.url_template) return
if (!this.options.overlay || !this.options.overlay.url_template) {
return
}
const overlay = this.createTileLayer(this.options.overlay)
try {
this.addLayer(overlay)
if (this.overlay) this.removeLayer(this.overlay)
if (this.overlay) {
this.removeLayer(this.overlay)
}
this.overlay = overlay
} catch (e) {
this.removeLayer(overlay)
@ -658,7 +719,9 @@ L.U.Map.include({
hasData: function () {
for (const datalayer of this.datalayers_index) {
if (datalayer.hasData()) return true
if (datalayer.hasData()) {
return true
}
}
},
@ -685,7 +748,9 @@ L.U.Map.include({
}
const datalayer = this.defaultDataLayer(),
feature = datalayer.getFeatureByIndex(-1)
if (feature) feature.zoomTo()
if (feature) {
feature.zoomTo()
}
})
} else {
this._setDefaultCenter()
@ -748,7 +813,9 @@ L.U.Map.include({
},
getOption: function (option) {
if (L.Util.usableOption(this.options, option)) return this.options[option]
if (L.Util.usableOption(this.options, option)) {
return this.options[option]
}
return this.getDefaultOption(option)
},
@ -773,12 +840,15 @@ L.U.Map.include({
self.options.tilelayer = tilelayer.toJSON()
self.isDirty = true
}
if (this._controls.tilelayers)
if (this._controls.tilelayers) {
this._controls.tilelayers.openSwitcher({ callback: callback, className: 'dark' })
}
},
manageDatalayers: function () {
if (this._controls.datalayers) this._controls.datalayers.openPanel()
if (this._controls.datalayers) {
this._controls.datalayers.openPanel()
}
},
toGeoJSON: function () {
@ -874,8 +944,12 @@ L.U.Map.include({
this.setView(this.latLng(this.options.center), this.options.zoom)
})
}
if (layerId) layer = map.datalayers[layerId]
if (layer && clearFlag.checked) layer.empty()
if (layerId) {
layer = map.datalayers[layerId]
}
if (layer && clearFlag.checked) {
layer.empty()
}
if (fileInput.files.length) {
let file
for (let i = 0, file; (file = fileInput.files[i]); i++) {
@ -893,16 +967,19 @@ L.U.Map.include({
this.importFromFile(file, 'umap')
} else {
let importLayer = layer
if (!layer) importLayer = this.createDataLayer({ name: file.name })
if (!layer) {
importLayer = this.createDataLayer({ name: file.name })
}
importLayer.importFromFile(file, type)
}
}
} else {
if (!type)
if (!type) {
return this.ui.alert({
content: L._('Please choose a format'),
level: 'error',
})
}
if (rawInput.value && type === 'umap') {
try {
this.importRaw(rawInput.value, type)
@ -911,11 +988,16 @@ L.U.Map.include({
console.error(e)
}
} else {
if (!layer) layer = this.createDataLayer()
if (rawInput.value) layer.importRaw(rawInput.value, type)
else if (urlInput.value) layer.importFromUrl(urlInput.value, type)
else if (presetSelect.selectedIndex > 0)
if (!layer) {
layer = this.createDataLayer()
}
if (rawInput.value) {
layer.importRaw(rawInput.value, type)
} else if (urlInput.value) {
layer.importFromUrl(urlInput.value, type)
} else if (presetSelect.selectedIndex > 0) {
layer.importFromUrl(presetSelect[presetSelect.selectedIndex].value, type)
}
}
}
}
@ -928,7 +1010,9 @@ L.U.Map.include({
newType
for (let i = 0; i < e.target.files.length; i++) {
newType = L.Util.detectFileType(e.target.files[i])
if (!type && newType) type = newType
if (!type && newType) {
type = newType
}
if (type && newType !== type) {
type = ''
break
@ -950,11 +1034,15 @@ L.U.Map.include({
const option = this.editableOptions[i]
if (typeof importedData.properties[option] !== 'undefined') {
this.options[option] = importedData.properties[option]
if (option === 'sortKey') mustReindex = true
if (option === 'sortKey') {
mustReindex = true
}
}
}
if (importedData.geometry) this.options.center = this.latLng(importedData.geometry)
if (importedData.geometry) {
this.options.center = this.latLng(importedData.geometry)
}
const self = this
importedData.layers.forEach((geojson) => {
delete geojson._umap_options['id'] // Never trust an id at this stage
@ -966,7 +1054,9 @@ L.U.Map.include({
this.renderControls()
this.handleLimitBounds()
this.eachDataLayer((datalayer) => {
if (mustReindex) datalayer.reindex()
if (mustReindex) {
datalayer.reindex()
}
datalayer.redraw()
})
this.fire('postsync')
@ -1011,7 +1101,9 @@ L.U.Map.include({
eachDataLayerReverse: function (method, context, filter) {
for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
if (filter && !filter.call(context, this.datalayers_index[i])) continue
if (filter && !filter.call(context, this.datalayers_index[i])) {
continue
}
method.call(context, this.datalayers_index[i])
}
},
@ -1026,8 +1118,9 @@ L.U.Map.include({
findDataLayer: function (method, context) {
for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
if (method.call(context, this.datalayers_index[i]))
if (method.call(context, this.datalayers_index[i])) {
return this.datalayers_index[i]
}
}
},
@ -1037,11 +1130,15 @@ L.U.Map.include({
},
reset: function () {
if (this.editTools) this.editTools.stopDrawing()
if (this.editTools) {
this.editTools.stopDrawing()
}
this.resetOptions()
this.datalayers_index = [].concat(this._datalayers_index_bk)
this.dirty_datalayers.slice().forEach((datalayer) => {
if (datalayer.isDeleted) datalayer.connectToMap()
if (datalayer.isDeleted) {
datalayer.connectToMap()
}
datalayer.reset()
})
this.ensurePanesOrder()
@ -1070,8 +1167,11 @@ L.U.Map.include({
},
continueSaving: function () {
if (this.dirty_datalayers.length) this.dirty_datalayers[0].save()
else this.fire('saved')
if (this.dirty_datalayers.length) {
this.dirty_datalayers[0].save()
} else {
this.fire('saved')
}
},
editableOptions: [
@ -1221,9 +1321,11 @@ L.U.Map.include({
this.permissions.commit()
}
// Update URL in case the name has changed.
if (history && history.pushState)
if (history && history.pushState) {
history.pushState({}, this.options.name, data.url)
else window.location = data.url
} else {
window.location = data.url
}
alert.content = data.info || alert.content
this.once('saved', () => this.ui.alert(alert))
this.ui.closePanel()
@ -1233,8 +1335,12 @@ L.U.Map.include({
},
save: function () {
if (!this.isDirty) return
if (this._default_extent) this.updateExtent()
if (!this.isDirty) {
return
}
if (this._default_extent) {
this.updateExtent()
}
this.backup()
this.once('saved', () => {
this.isDirty = false
@ -1276,11 +1382,12 @@ L.U.Map.include({
},
star: function () {
if (!this.options.umap_id)
if (!this.options.umap_id) {
return this.ui.alert({
content: L._('Please save the map first'),
level: 'error',
})
}
let url = L.Util.template(this.options.urls.map_star, {
map_id: this.options.umap_id,
})
@ -1323,10 +1430,14 @@ L.U.Map.include({
datalayer = this.findDataLayer((datalayer) => {
if (!datalayer.isDataReadOnly() && datalayer.canBrowse()) {
fallback = datalayer
if (datalayer.isVisible()) return true
if (datalayer.isVisible()) {
return true
}
}
})
if (datalayer) return datalayer
if (datalayer) {
return datalayer
}
if (fallback) {
// No datalayer visible, let's force one
this.addLayer(fallback.layer)
@ -1447,7 +1558,9 @@ L.U.Map.include({
callback: function (e) {
this.initCaptionBar()
this.eachDataLayer((datalayer) => {
if (e.helper.field === 'options.sortKey') datalayer.reindex()
if (e.helper.field === 'options.sortKey') {
datalayer.reindex()
}
datalayer.redraw()
})
},
@ -1475,8 +1588,9 @@ L.U.Map.include({
e.helper.field === 'options.popupTemplate' ||
e.helper.field === 'options.popupContentTemplate' ||
e.helper.field === 'options.popupShape'
)
) {
return
}
this.eachDataLayer((datalayer) => {
datalayer.redraw()
})
@ -1774,8 +1888,12 @@ L.U.Map.include({
},
edit: function () {
if (!this.editEnabled) return
if (this.options.editMode !== 'advanced') return
if (!this.editEnabled) {
return
}
if (this.options.editMode !== 'advanced') {
return
}
const container = L.DomUtil.create('div', 'umap-edit-container'),
metadataFields = ['options.name', 'options.description'],
title = L.DomUtil.create('h3', '', container)
@ -1804,7 +1922,9 @@ L.U.Map.include({
},
disableEdit: function () {
if (this.isDirty) return
if (this.isDirty) {
return
}
L.DomUtil.removeClass(document.body, 'umap-edit-enabled')
this.editedFeature = null
this.editEnabled = false
@ -1877,7 +1997,9 @@ L.U.Map.include({
},
askForReset: function (e) {
if (!confirm(L._('Are you sure you want to cancel your changes?'))) return
if (!confirm(L._('Are you sure you want to cancel your changes?'))) {
return
}
this.reset()
this.disableEdit(e)
this.ui.closePanel()
@ -2096,11 +2218,15 @@ L.U.Map.include({
closeInplaceToolbar: function () {
const toolbar = this._toolbars[L.Toolbar.Popup._toolbar_class_id]
if (toolbar) toolbar.remove()
if (toolbar) {
toolbar.remove()
}
},
search: function () {
if (this._controls.search) this._controls.search.openPanel(this)
if (this._controls.search) {
this._controls.search.openPanel(this)
}
},
getFilterKeys: function () {
@ -2118,7 +2244,9 @@ L.U.Map.include({
getLayersBounds: function () {
const bounds = new L.latLngBounds()
this.eachBrowsableDataLayer((d) => {
if (d.isVisible()) bounds.extend(d.layer.getBounds())
if (d.isVisible()) {
bounds.extend(d.layer.getBounds())
}
})
return bounds
},

View file

@ -141,7 +141,9 @@ L.U.Layer.Heat = L.HeatLayer.extend({
// setlalngs call _redraw through setAnimFrame, thus async, so this
// can ends with race condition if we remove the layer very faslty after.
// Remove me when https://github.com/Leaflet/Leaflet.heat/pull/53 is released.
if (!this._map) return
if (!this._map) {
return
}
L.HeatLayer.prototype.redraw.call(this)
},
@ -219,13 +221,17 @@ L.U.DataLayer = L.Evented.extend({
return isDirty
},
set: function (status) {
if (!isDirty && status) self.fire('dirty')
if (!isDirty && status) {
self.fire('dirty')
}
isDirty = status
if (status) {
self.map.addDirtyDatalayer(self)
// A layer can be made dirty by indirect action (like dragging layers)
// we need to have it loaded before saving it.
if (!self.isLoaded()) self.fetchData()
if (!self.isLoaded()) {
self.fetchData()
}
} else {
self.map.removeDirtyDatalayer(self)
self.isDeleted = false
@ -241,9 +247,13 @@ L.U.DataLayer = L.Evented.extend({
return isDeleted
},
set: function (status) {
if (!isDeleted && status) self.fire('deleted')
if (!isDeleted && status) {
self.fire('deleted')
}
isDeleted = status
if (status) self.isDirty = status
if (status) {
self.isDirty = status
}
},
})
} catch (e) {
@ -263,8 +273,12 @@ L.U.DataLayer = L.Evented.extend({
this.backupOptions()
this.connectToMap()
this.permissions = new L.U.DataLayerPermissions(this)
if (this.showAtLoad()) this.show()
if (!this.umap_id) this.isDirty = true
if (this.showAtLoad()) {
this.show()
}
if (!this.umap_id) {
this.isDirty = true
}
this.onceLoaded(function () {
this.map.on('moveend', this.onMoveEnd, this)
@ -272,17 +286,27 @@ L.U.DataLayer = L.Evented.extend({
// Only layers that are displayed on load must be hidden/shown
// Automatically, others will be shown manually, and thus will
// be in the "forced visibility" mode
if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this)
if (this.autoLoaded()) {
this.map.on('zoomend', this.onZoomEnd, this)
}
},
onMoveEnd: function (e) {
if (this.isRemoteLayer() && this.showAtZoom()) this.fetchRemoteData()
if (this.isRemoteLayer() && this.showAtZoom()) {
this.fetchRemoteData()
}
},
onZoomEnd: function (e) {
if (this._forcedVisibility) return
if (!this.showAtZoom() && this.isVisible()) this.hide()
if (this.showAtZoom() && !this.isVisible()) this.show()
if (this._forcedVisibility) {
return
}
if (!this.showAtZoom() && this.isVisible()) {
this.hide()
}
if (this.showAtZoom() && !this.isVisible()) {
this.show()
}
},
showAtLoad: function () {
@ -299,12 +323,16 @@ L.U.DataLayer = L.Evented.extend({
},
insertBefore: function (other) {
if (!other) return
if (!other) {
return
}
this.parentPane.insertBefore(this.pane, other.pane)
},
insertAfter: function (other) {
if (!other) return
if (!other) {
return
}
this.parentPane.insertBefore(this.pane, other.pane.nextSibling)
},
@ -318,15 +346,27 @@ L.U.DataLayer = L.Evented.extend({
resetLayer: function (force) {
// Only reset if type is defined (undefined is the default) and different from current type
if (this.layer && (!this.options.type || this.options.type === this.layer._type) && !force) return
if (
this.layer &&
(!this.options.type || this.options.type === this.layer._type) &&
!force
) {
return
}
const visible = this.isVisible()
if (this.layer) this.layer.clearLayers()
if (this.layer) {
this.layer.clearLayers()
}
// delete this.layer?
if (visible) this.map.removeLayer(this.layer)
if (visible) {
this.map.removeLayer(this.layer)
}
const Class = L.U.Layer[this.options.type] || L.U.Layer.Default
this.layer = new Class(this)
this.eachLayer((feature) => this.showFeature(feature))
if (visible) this.show()
if (visible) {
this.show()
}
this.propagateRemote()
},
@ -347,8 +387,12 @@ L.U.DataLayer = L.Evented.extend({
},
fetchData: function () {
if (!this.umap_id) return
if (this._loading) return
if (!this.umap_id) {
return
}
if (this._loading) {
return
}
this._loading = true
this.map.get(this._dataUrl(), {
callback: function (geojson, response) {
@ -358,9 +402,13 @@ L.U.DataLayer = L.Evented.extend({
// So do not let all options to be reset
// Fix is a proper migration so all datalayers settings are
// in DB, and we remove it from geojson flat files.
if (geojson._umap_options) geojson._umap_options.editMode = this.options.editMode
if (geojson._umap_options) {
geojson._umap_options.editMode = this.options.editMode
}
// In case of maps pre 1.0 still around
if (geojson._storage) geojson._storage.editMode = this.options.editMode
if (geojson._storage) {
geojson._storage.editMode = this.options.editMode
}
this.fromUmapGeoJSON(geojson)
this.backupOptions()
this.fire('loaded')
@ -379,10 +427,17 @@ L.U.DataLayer = L.Evented.extend({
},
fromUmapGeoJSON: function (geojson) {
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat
if (geojson._umap_options) this.setOptions(geojson._umap_options)
if (this.isRemoteLayer()) this.fetchRemoteData()
else this.fromGeoJSON(geojson)
if (geojson._storage) {
geojson._umap_options = geojson._storage
} // Retrocompat
if (geojson._umap_options) {
this.setOptions(geojson._umap_options)
}
if (this.isRemoteLayer()) {
this.fetchRemoteData()
} else {
this.fromGeoJSON(geojson)
}
this._loaded = true
},
@ -419,12 +474,19 @@ L.U.DataLayer = L.Evented.extend({
},
fetchRemoteData: function (force) {
if (!this.isRemoteLayer()) return
if (!this.options.remoteData.dynamic && this.hasDataLoaded() && !force) return
if (!this.isVisible()) return
if (!this.isRemoteLayer()) {
return
}
if (!this.options.remoteData.dynamic && this.hasDataLoaded() && !force) {
return
}
if (!this.isVisible()) {
return
}
let url = this.map.localizeUrl(this.options.remoteData.url)
if (this.options.remoteData.proxy)
if (this.options.remoteData.proxy) {
url = this.map.proxyUrl(url, this.options.remoteData.ttl)
}
this.map.ajax({
uri: url,
verb: 'GET',
@ -439,14 +501,20 @@ L.U.DataLayer = L.Evented.extend({
},
onceLoaded: function (callback, context) {
if (this.isLoaded()) callback.call(context || this, this)
else this.once('loaded', callback, context)
if (this.isLoaded()) {
callback.call(context || this, this)
} else {
this.once('loaded', callback, context)
}
return this
},
onceDataLoaded: function (callback, context) {
if (this.hasDataLoaded()) callback.call(context || this, this)
else this.once('dataloaded', callback, context)
if (this.hasDataLoaded()) {
callback.call(context || this, this)
} else {
this.once('dataloaded', callback, context)
}
return this
},
@ -460,7 +528,9 @@ L.U.DataLayer = L.Evented.extend({
setUmapId: function (id) {
// Datalayer is null when listening creation form
if (!this.umap_id && id) this.umap_id = id
if (!this.umap_id && id) {
this.umap_id = id
}
},
backupOptions: function () {
@ -485,8 +555,9 @@ L.U.DataLayer = L.Evented.extend({
const id = L.stamp(this)
if (!this.map.datalayers[id]) {
this.map.datalayers[id] = this
if (L.Util.indexOf(this.map.datalayers_index, this) === -1)
if (L.Util.indexOf(this.map.datalayers_index, this) === -1) {
this.map.datalayers_index.push(this)
}
}
this.map.updateDatalayersControl()
},
@ -500,7 +571,9 @@ L.U.DataLayer = L.Evented.extend({
})
// No browser cache for owners/editors.
if (this.map.hasEditMode()) url = `${url}?${Date.now()}`
if (this.map.hasEditMode()) {
url = `${url}?${Date.now()}`
}
return url
},
@ -519,8 +592,12 @@ L.U.DataLayer = L.Evented.extend({
showFeature: function (feature) {
const filterKeys = this.map.getFilterKeys(),
filter = this.map.options.filter
if (filter && !feature.matchFilter(filter, filterKeys)) return
if (!feature.matchFacets()) return
if (filter && !feature.matchFilter(filter, filterKeys)) {
return
}
if (!feature.matchFacets()) {
return
}
this.layer.addLayer(feature)
},
@ -532,7 +609,9 @@ L.U.DataLayer = L.Evented.extend({
this.indexProperties(feature)
this.map.features_index[feature.getSlug()] = feature
this.showFeature(feature)
if (this.hasDataLoaded()) this.fire('datachanged')
if (this.hasDataLoaded()) {
this.fire('datachanged')
}
},
removeLayer: function (feature) {
@ -542,24 +621,38 @@ L.U.DataLayer = L.Evented.extend({
delete this._layers[id]
this.layer.removeLayer(feature)
delete this.map.features_index[feature.getSlug()]
if (this.hasDataLoaded()) this.fire('datachanged')
if (this.hasDataLoaded()) {
this.fire('datachanged')
}
},
indexProperties: function (feature) {
for (const i in feature.properties)
for (const i in feature.properties) {
if (typeof feature.properties[i] !== 'object') this.indexProperty(i)
}
if (typeof feature.properties[i] !== 'object') {
this.indexProperty(i)
}
},
indexProperty: function (name) {
if (!name) return
if (name.indexOf('_') === 0) return
if (L.Util.indexOf(this._propertiesIndex, name) !== -1) return
if (!name) {
return
}
if (name.indexOf('_') === 0) {
return
}
if (L.Util.indexOf(this._propertiesIndex, name) !== -1) {
return
}
this._propertiesIndex.push(name)
},
deindexProperty: function (name) {
const idx = this._propertiesIndex.indexOf(name)
if (idx !== -1) this._propertiesIndex.splice(idx, 1)
if (idx !== -1) {
this._propertiesIndex.splice(idx, 1)
}
},
addData: function (geojson) {
@ -633,7 +726,9 @@ L.U.DataLayer = L.Evented.extend({
},
geojsonToFeatures: function (geojson) {
if (!geojson) return
if (!geojson) {
return
}
const features = geojson instanceof Array ? geojson : geojson.features
let i
let len
@ -649,7 +744,9 @@ L.U.DataLayer = L.Evented.extend({
}
const geometry = geojson.type === 'Feature' ? geojson.geometry : geojson
if (!geometry) return // null geometry is valid geojson.
if (!geometry) {
return
} // null geometry is valid geojson.
const coords = geometry.coordinates
let layer
let tmp
@ -671,7 +768,9 @@ L.U.DataLayer = L.Evented.extend({
coords,
geometry.type === 'LineString' ? 0 : 1
)
if (!latlngs.length) break
if (!latlngs.length) {
break
}
layer = this._lineToLayer(geojson, latlngs)
break
@ -794,7 +893,9 @@ L.U.DataLayer = L.Evented.extend({
},
empty: function () {
if (this.isRemoteLayer()) return
if (this.isRemoteLayer()) {
return
}
this.clear()
this.isDirty = true
},
@ -824,7 +925,9 @@ L.U.DataLayer = L.Evented.extend({
},
reset: function () {
if (!this.umap_id) this.erase()
if (!this.umap_id) {
this.erase()
}
this.resetOptions()
this.parentPane.appendChild(this.pane)
@ -833,8 +936,11 @@ L.U.DataLayer = L.Evented.extend({
}
this.clear()
this.hide()
if (this.isRemoteLayer()) this.fetchRemoteData()
else if (this._geojson_bk) this.fromGeoJSON(this._geojson_bk)
if (this.isRemoteLayer()) {
this.fetchRemoteData()
} else if (this._geojson_bk) {
this.fromGeoJSON(this._geojson_bk)
}
this._loaded = true
this.show()
this.isDirty = false
@ -990,7 +1096,9 @@ L.U.DataLayer = L.Evented.extend({
this
)
if (this.map.options.urls.datalayer_versions) this.buildVersionsFieldset(container)
if (this.map.options.urls.datalayer_versions) {
this.buildVersionsFieldset(container)
}
const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions)
@ -1043,8 +1151,11 @@ L.U.DataLayer = L.Evented.extend({
},
getOption: function (option) {
if (L.Util.usableOption(this.options, option)) return this.options[option]
else return this.map.getOption(option)
if (L.Util.usableOption(this.options, option)) {
return this.options[option]
} else {
return this.map.getOption(option)
}
},
buildVersionsFieldset: function (container) {
@ -1080,15 +1191,26 @@ L.U.DataLayer = L.Evented.extend({
},
restore: function (version) {
if (!this.map.editEnabled) return
if (!confirm(L._('Are you sure you want to restore this version?'))) return
if (!this.map.editEnabled) {
return
}
if (!confirm(L._('Are you sure you want to restore this version?'))) {
return
}
this.map.xhr.get(this.getVersionUrl(version), {
callback: function (geojson) {
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat.
if (geojson._umap_options) this.setOptions(geojson._umap_options)
if (geojson._storage) {
geojson._umap_options = geojson._storage
} // Retrocompat.
if (geojson._umap_options) {
this.setOptions(geojson._umap_options)
}
this.empty()
if (this.isRemoteLayer()) this.fetchRemoteData()
else this.addData(geojson)
if (this.isRemoteLayer()) {
this.fetchRemoteData()
} else {
this.addData(geojson)
}
this.isDirty = true
},
context: this,
@ -1102,7 +1224,9 @@ L.U.DataLayer = L.Evented.extend({
},
show: function () {
if (!this.isLoaded()) this.fetchData()
if (!this.isLoaded()) {
this.fetchData()
}
this.map.addLayer(this.layer)
this.fire('show')
},
@ -1116,14 +1240,21 @@ L.U.DataLayer = L.Evented.extend({
// From now on, do not try to how/hide
// automatically this layer.
this._forcedVisibility = true
if (!this.isVisible()) this.show()
else this.hide()
if (!this.isVisible()) {
this.show()
} else {
this.hide()
}
},
zoomTo: function () {
if (!this.isVisible()) return
if (!this.isVisible()) {
return
}
const bounds = this.layer.getBounds()
if (bounds.isValid()) this.map.fitBounds(bounds)
if (bounds.isValid()) {
this.map.fitBounds(bounds)
}
},
allowBrowse: function () {
@ -1143,7 +1274,9 @@ L.U.DataLayer = L.Evented.extend({
},
getFeatureByIndex: function (index) {
if (index === -1) index = this._index.length - 1
if (index === -1) {
index = this._index.length - 1
}
const id = this._index[index]
return this._layers[id]
},
@ -1170,7 +1303,9 @@ L.U.DataLayer = L.Evented.extend({
let next
const index = this.map.datalayers_index
while (((id = index[++id] ? id : 0), (next = index[id]))) {
if (next === this || (next.allowBrowse() && next.hasData())) break
if (next === this || (next.allowBrowse() && next.hasData())) {
break
}
}
return next
},
@ -1180,7 +1315,9 @@ L.U.DataLayer = L.Evented.extend({
let prev
const index = this.map.datalayers_index
while (((id = index[--id] ? id : index.length - 1), (prev = index[id]))) {
if (prev === this || (prev.allowBrowse() && prev.hasData())) break
if (prev === this || (prev.allowBrowse() && prev.hasData())) {
break
}
}
return prev
},
@ -1208,7 +1345,9 @@ L.U.DataLayer = L.Evented.extend({
},
save: function () {
if (this.isDeleted) return this.saveDelete()
if (this.isDeleted) {
return this.saveDelete()
}
if (!this.isLoaded()) {
return
}
@ -1247,7 +1386,9 @@ L.U.DataLayer = L.Evented.extend({
this.isDirty = false
this.map.continueSaving()
}
if (!this.umap_id) return callback.call(this)
if (!this.umap_id) {
return callback.call(this)
}
this.map.xhr.post(this.getDeleteUrl(), {
callback: callback,
context: this,
@ -1263,7 +1404,9 @@ L.U.DataLayer = L.Evented.extend({
},
tableEdit: function () {
if (this.isRemoteLayer() || !this.isVisible()) return
if (this.isRemoteLayer() || !this.isVisible()) {
return
}
const editor = new L.U.TableEditor(this)
editor.edit()
},

View file

@ -51,12 +51,15 @@ L.U.MapPermissions = L.Class.extend({
},
edit: function () {
if (this.map.options.editMode !== 'advanced') return
if (!this.map.options.umap_id)
if (this.map.options.editMode !== 'advanced') {
return
}
if (!this.map.options.umap_id) {
return this.map.ui.alert({
content: L._('Please save the map first'),
level: 'info',
})
}
const container = L.DomUtil.create('div', 'permissions-panel'),
fields = [],
title = L.DomUtil.create('h4', '', container)
@ -148,15 +151,19 @@ L.U.MapPermissions = L.Class.extend({
},
save: function () {
if (!this.isDirty) return this.map.continueSaving()
if (!this.isDirty) {
return this.map.continueSaving()
}
const formData = new FormData()
if (!this.isAnonymousMap() && this.options.editors) {
const editors = this.options.editors.map((u) => u.id)
for (let i = 0; i < this.options.editors.length; i++)
for (let i = 0; i < this.options.editors.length; i++) {
formData.append('editors', this.options.editors[i].id)
}
}
if (this.isOwner() || this.isAnonymousMap())
if (this.isOwner() || this.isAnonymousMap()) {
formData.append('edit_status', this.options.edit_status)
}
if (this.isOwner()) {
formData.append('owner', this.options.owner && this.options.owner.id)
formData.append('share_status', this.options.share_status)

View file

@ -107,7 +107,7 @@ L.U.PopupTemplate.Default = L.Class.extend({
properties
)
content = L.Util.greedyTemplate(template, properties)
content = L.Util.toHTML(content, {target: target})
content = L.Util.toHTML(content, { target: target })
container.innerHTML = content
return container
},
@ -120,20 +120,26 @@ L.U.PopupTemplate.Default = L.Class.extend({
nextLi = L.DomUtil.create('li', 'next', footer),
next = this.feature.getNext(),
prev = this.feature.getPrevious()
if (next)
if (next) {
nextLi.title = L._('Go to «{feature}»', {
feature: next.properties.name || L._('next'),
})
if (prev)
}
if (prev) {
previousLi.title = L._('Go to «{feature}»', {
feature: prev.properties.name || L._('previous'),
})
}
zoomLi.title = L._('Zoom to this feature')
L.DomEvent.on(nextLi, 'click', () => {
if (next) next.zoomTo({ callback: next.view })
if (next) {
next.zoomTo({ callback: next.view })
}
})
L.DomEvent.on(previousLi, 'click', () => {
if (prev) prev.zoomTo({ callback: prev.view })
if (prev) {
prev.zoomTo({ callback: prev.view })
}
})
L.DomEvent.on(
zoomLi,
@ -148,9 +154,13 @@ L.U.PopupTemplate.Default = L.Class.extend({
render: function () {
const title = this.renderTitle()
if (title) this.container.appendChild(title)
if (title) {
this.container.appendChild(title)
}
const body = this.renderBody()
if (body) L.DomUtil.add('div', 'umap-popup-content', this.container, body)
if (body) {
L.DomUtil.add('div', 'umap-popup-content', this.container, body)
}
this.renderFooter()
},
})
@ -184,7 +194,9 @@ L.U.PopupTemplate.Table = L.U.PopupTemplate.BaseWithTitle.extend({
const table = L.DomUtil.create('table')
for (const key in this.feature.properties) {
if (typeof this.feature.properties[key] === 'object' || key === 'name') continue
if (typeof this.feature.properties[key] === 'object' || key === 'name') {
continue
}
// TODO, manage links (url, mailto, wikipedia...)
this.addRow(table, key, L.Util.escapeHTML(this.feature.properties[key]).trim())
}

View file

@ -22,7 +22,9 @@ L.U.Slideshow = L.Class.extend({
get: function () {
if (!current) {
const datalayer = this.defaultDatalayer()
if (datalayer) current = datalayer.getFeatureByIndex(0)
if (datalayer) {
current = datalayer.getFeatureByIndex(0)
}
}
return current
},
@ -70,7 +72,9 @@ L.U.Slideshow = L.Class.extend({
timeSpinner: function () {
const time = parseInt(this.options.delay, 10)
if (!time) return
if (!time) {
return
}
const css = `rotation ${time / 1000}s infinite linear`,
spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner')
for (let i = 0; i < spinners.length; i++) {
@ -95,8 +99,12 @@ L.U.Slideshow = L.Class.extend({
},
play: function () {
if (this._id) return
if (this.map.editEnabled || !this.map.options.slideshow.active) return
if (this._id) {
return
}
if (this.map.editEnabled || !this.map.options.slideshow.active) {
return
}
L.DomUtil.addClass(document.body, L.U.Slideshow.CLASSNAME)
this._id = window.setInterval(L.bind(this.loop, this), this.options.delay)
this.resetSpinners()
@ -129,12 +137,16 @@ L.U.Slideshow = L.Class.extend({
backward: function () {
this.pause()
if (this.current) this.current = this.current.getPrevious()
if (this.current) {
this.current = this.current.getPrevious()
}
this.step()
},
step: function () {
if (!this.current) return this.stop()
if (!this.current) {
return this.stop()
}
this.current.zoomTo({ easing: this.options.easing })
this.current.view()
},
@ -151,8 +163,11 @@ L.U.Slideshow = L.Class.extend({
next.title = L._('Zoom to the next')
prev.title = L._('Zoom to the previous')
const toggle = function () {
if (this._id) this.pause()
else this.play()
if (this._id) {
this.pause()
} else {
this.play()
}
}
L.DomEvent.on(play, 'click', L.DomEvent.stop).on(play, 'click', toggle, this)
L.DomEvent.on(stop, 'click', L.DomEvent.stop).on(stop, 'click', this.stop, this)

View file

@ -40,7 +40,9 @@ L.U.TableEditor = L.Class.extend({
L._('Please enter the new name of this property'),
property
)
if (!newName || !this.validateName(newName)) return
if (!newName || !this.validateName(newName)) {
return
}
this.datalayer.eachLayer((feature) => {
feature.renameProperty(property, newName)
})
@ -63,10 +65,13 @@ L.U.TableEditor = L.Class.extend({
},
compileProperties: function () {
if (this.properties.length === 0) this.properties = ['name']
if (this.properties.length === 0) {
this.properties = ['name']
}
// description is a forced textarea, don't edit it in a text input, or you lose cariage returns
if (this.properties.indexOf('description') !== -1)
if (this.properties.indexOf('description') !== -1) {
this.properties.splice(this.properties.indexOf('description'), 1)
}
this.properties.sort()
this.field_properties = []
for (let i = 0; i < this.properties.length; i++) {
@ -105,7 +110,9 @@ L.U.TableEditor = L.Class.extend({
label.textContent = label.title = L._('Add a new property')
const addProperty = function () {
const newName = prompt(L._('Please enter the name of the property'))
if (!newName || !this.validateName(newName)) return
if (!newName || !this.validateName(newName)) {
return
}
this.datalayer.indexProperty(newName)
this.edit()
}

View file

@ -33,9 +33,11 @@ L.U.UI = L.Evented.extend({
this._panel.innerHTML = ''
const actionsContainer = L.DomUtil.create('ul', 'toolbox', this._panel)
const body = L.DomUtil.create('div', 'body', this._panel)
if (e.data.html.nodeType && e.data.html.nodeType === 1)
if (e.data.html.nodeType && e.data.html.nodeType === 1) {
body.appendChild(e.data.html)
else body.innerHTML = e.data.html
} else {
body.innerHTML = e.data.html
}
const closeLink = L.DomUtil.create('li', 'umap-close-link', actionsContainer)
L.DomUtil.add('i', 'umap-close-icon', closeLink)
const label = L.DomUtil.create('span', '', closeLink)
@ -45,7 +47,9 @@ L.U.UI = L.Evented.extend({
actionsContainer.appendChild(e.actions[i])
}
}
if (e.className) L.DomUtil.addClass(this._panel, e.className)
if (e.className) {
L.DomUtil.addClass(this._panel, e.className)
}
if (L.DomUtil.hasClass(this.parent, 'umap-ui')) {
// Already open.
this.fire('panel:ready')
@ -69,14 +73,20 @@ L.U.UI = L.Evented.extend({
},
alert: function (e) {
if (L.DomUtil.hasClass(this.parent, 'umap-alert')) this.ALERTS.push(e)
else this.popAlert(e)
if (L.DomUtil.hasClass(this.parent, 'umap-alert')) {
this.ALERTS.push(e)
} else {
this.popAlert(e)
}
},
popAlert: function (e) {
if (!e) {
if (this.ALERTS.length) e = this.ALERTS.pop()
else return
if (this.ALERTS.length) {
e = this.ALERTS.pop()
} else {
return
}
}
let timeoutID
const level_class = e.level && e.level == 'info' ? 'info' : 'error'
@ -90,7 +100,9 @@ L.U.UI = L.Evented.extend({
this._alert.innerHTML = ''
L.DomUtil.removeClass(this.parent, 'umap-alert')
L.DomUtil.removeClass(this._alert, level_class)
if (timeoutID) window.clearTimeout(timeoutID)
if (timeoutID) {
window.clearTimeout(timeoutID)
}
this.popAlert()
}
const closeLink = L.DomUtil.create('a', 'umap-close-link', this._alert)
@ -143,16 +155,23 @@ L.U.UI = L.Evented.extend({
this.TOOLTIP_ID = Math.random()
const id = this.TOOLTIP_ID
L.DomUtil.addClass(this.parent, 'umap-tooltip')
if (e.anchor && e.position === 'top') this.anchorTooltipTop(e.anchor)
else if (e.anchor && e.position === 'left') this.anchorTooltipLeft(e.anchor)
else this.anchorTooltipAbsolute()
if (e.anchor && e.position === 'top') {
this.anchorTooltipTop(e.anchor)
} else if (e.anchor && e.position === 'left') {
this.anchorTooltipLeft(e.anchor)
} else {
this.anchorTooltipAbsolute()
}
this._tooltip.innerHTML = e.content
function closeIt() {
this.closeTooltip(id)
}
if (e.anchor) L.DomEvent.once(e.anchor, 'mouseout', closeIt, this)
if (e.duration !== Infinity)
if (e.anchor) {
L.DomEvent.once(e.anchor, 'mouseout', closeIt, this)
}
if (e.duration !== Infinity) {
window.setTimeout(L.bind(closeIt, this), e.duration || 3000)
}
},
anchorTooltipAbsolute: function () {
@ -184,7 +203,9 @@ L.U.UI = L.Evented.extend({
},
closeTooltip: function (id) {
if (id && id !== this.TOOLTIP_ID) return
if (id && id !== this.TOOLTIP_ID) {
return
}
this._tooltip.innerHTML = ''
L.DomUtil.removeClass(this.parent, 'umap-tooltip')
},
@ -194,14 +215,26 @@ L.U.UI = L.Evented.extend({
},
setTooltipPosition: function (coords) {
if (coords.left) this._tooltip.style.left = `${coords.left}px`
else this._tooltip.style.left = 'initial'
if (coords.right) this._tooltip.style.right = `${coords.right}px`
else this._tooltip.style.right = 'initial'
if (coords.top) this._tooltip.style.top = `${coords.top}px`
else this._tooltip.style.top = 'initial'
if (coords.bottom) this._tooltip.style.bottom = `${coords.bottom}px`
else this._tooltip.style.bottom = 'initial'
if (coords.left) {
this._tooltip.style.left = `${coords.left}px`
} else {
this._tooltip.style.left = 'initial'
}
if (coords.right) {
this._tooltip.style.right = `${coords.right}px`
} else {
this._tooltip.style.right = 'initial'
}
if (coords.top) {
this._tooltip.style.top = `${coords.top}px`
} else {
this._tooltip.style.top = 'initial'
}
if (coords.bottom) {
this._tooltip.style.bottom = `${coords.bottom}px`
} else {
this._tooltip.style.bottom = 'initial'
}
},
getDocHeight: function () {

View file

@ -159,12 +159,17 @@ L.U.Xhr = L.Evented.extend({
self.ui.alert({ content: L._('An error occured'), level: 'error' })
} else if (data.login_required) {
// login_required should be an URL for the login form
if (settings.login_callback) settings.login_callback(data)
else self.login(data, args)
if (settings.login_callback) {
settings.login_callback(data)
} else {
self.login(data, args)
}
} else {
if (settings.callback)
if (settings.callback) {
L.bind(settings.callback, settings.context || this)(data, response)
else self.default_callback(data, settings, response)
} else {
self.default_callback(data, settings, response)
}
}
}
@ -187,10 +192,14 @@ L.U.Xhr = L.Evented.extend({
},
submit_form: function (form_id, options) {
if (typeof options === 'undefined') options = {}
if (typeof options === 'undefined') {
options = {}
}
const form = L.DomUtil.get(form_id)
const formData = new FormData(form)
if (options.extraFormData) formData.append(options.extraFormData)
if (options.extraFormData) {
formData.append(options.extraFormData)
}
options.data = formData
this.post(form.action, options)
return false
@ -199,7 +208,9 @@ L.U.Xhr = L.Evented.extend({
listen_form: function (form_id, options) {
const form = L.DomUtil.get(form_id),
self = this
if (!form) return
if (!form) {
return
}
L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation)
.on(form, 'submit', L.DomEvent.preventDefault)
.on(form, 'submit', () => {
@ -224,9 +235,11 @@ L.U.Xhr = L.Evented.extend({
// default callback, to avoid boilerplate
if (data.redirect) {
const newPath = data.redirect
if (window.location.pathname == newPath)
window.location.reload() // Keep the hash, so the current view
else window.location = newPath
if (window.location.pathname == newPath) {
window.location.reload()
} else {
window.location = newPath
}
} else if (data.info) {
this.ui.alert({ content: data.info, level: 'info' })
this.ui.closePanel()
@ -235,7 +248,9 @@ L.U.Xhr = L.Evented.extend({
} else if (data.html) {
const ui_options = { data: data }
let listen_options
if (options.className) ui_options.className = options.className
if (options.className) {
ui_options.className = options.className
}
this.ui.openPanel(ui_options)
// To low boilerplate, if there is a form, listen it
if (options.listen_form) {
@ -262,15 +277,21 @@ L.U.Xhr = L.Evented.extend({
const self = this
const proceed = () => {
self.ui.closePanel()
if (typeof args !== 'undefined') self._json.apply(self, args)
else self.default_callback(data, {})
if (typeof args !== 'undefined') {
self._json.apply(self, args)
} else {
self.default_callback(data, {})
}
}
const ask_for_login = (data) => {
self.ui.openPanel({ data: data, className: 'login-panel' })
self.listen_form('login_form', {
callback: function (data) {
if (data.html) ask_for_login(data) // Problem in the login - ask again
else proceed()
if (data.html) {
ask_for_login(data)
} else {
proceed()
}
},
})
// Auth links