Open xgqfrms opened 6 years ago
NodeList
to Array
let all_btns = document.querySelectorAll(`[data-uid="all"]`),
add_btns = document.querySelectorAll(`[data-uid="add"]`);
setTimeout(() => {
[...all_btns].forEach(
(btn, i) => {
btn.addEventListener(`click`, (e) => {
console.log(`all e =`, e);
});
}
);
[...add_btns].forEach(
(btn, i) => {
btn.addEventListener(`click`, (e) => {
console.log(`add e =`, e);
});
}
);
}, 0);
https://stackoverflow.com/questions/3547035/javascript-getting-html-form-values
https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_form_elements_index
function myFunction() {
var elements = document.getElementById("myForm").elements;
var obj ={};
for(var i = 0 ; i < elements.length ; i++){
var item = elements.item(i);
obj[item.name] = item.value;
}
document.getElementById("demo").innerHTML = JSON.stringify(obj);
}
https://www.html5rocks.com/en/tutorials/notifications/quick/
https://github.com/alexgibson/notify.js
https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web
https://www.home-assistant.io/components/notify.html5/
HTML5 Push Notifications
https://erpfm.com/html5-push-notifications/
https://erpfm.com/the-future-of-html5/
https://erpfm.com/what-are-push-notifications/
demo
http://www.bennish.net/web-notifications.html
W3C Recommendation 22 October 2015
http://www.webhek.com/post/preload-prefetch-and-priorities-in-chrome.html
https://www.davidwalsh.name/demo/notifications-api.php
https://davidwalsh.name/notifications-api
if(window.Notification && Notification.permission !== "denied") {
Notification.requestPermission(function(status) { // status is "granted", if accepted by user
var n = new Notification('Title', {
body: 'I am the body text!',
icon: '/path/to/icon.png' // optional
});
});
}
https://pusher.com/tutorials/realtime-notifications
https://www.binpress.com/tutorial/building-useful-notifications-with-html5-apis/163
http://dangercove.github.io/html5-notifications/
https://github.com/xgqfrms/HTML5
https://github.com/xgqfrms/HTML5/tree/gh-pages/history-api
https://www.renfei.org/blog/html5-introduction-3-history-api.html
const data = {
"name": "test",
"pro_type": "Base",
"src_path": "xxx",
"release_path": "xxx",
"svn_user": "xyz",
"org.gil.server.report": "on",
"Robots": "on"
};
undefined
let keys = Object.keys(data);
// undefined
let result = [];
for (let i = 0; i < keys.length; i++) {
if (data[keys[i]] !== "on") {
result.push(keys[i]);
}
}
// undefined
keys;
// (7) ["name", "pro_type", "src_path", "release_path", "svn_user", "org.gil.server.report", "Robots"]
result
// (5) ["name", "pro_type", "src_path", "release_path", "svn_user"]
result = [];
for (let i = 0; i < keys.length; i++) {
if (data[keys[i]] === "on") {
result.push(keys[i]);
}
}
// 2
result;
// (2) ["org.gil.server.report", "Robots"]
JSON.stringify();
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
let bp = DependencesProjects.indexOf(data.pro_name);
DependencesProjects.splice(bp, 1);
// update
localStorage.setItem(`depend_pro_names`, DependencesProjects);
array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
var maxCallback = ( acc, cur ) => Math.max( acc.x, cur.x );
var maxCallback2 = ( max, cur ) => Math.max( max, cur );
// reduce() without initialValue
[ { x: 22 }, { x: 42 } ].reduce( maxCallback ); // 42
[ { x: 22 } ].reduce( maxCallback ); // { x: 22 }
[ ].reduce( maxCallback ); // TypeError
// map/reduce; better solution, also works for empty or larger arrays
[ { x: 22 }, { x: 42 } ]
.map( el => el.x )
.reduce( maxCallback2, -Infinity );
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
var arr1 = [1, 2, 3, 4];
arr1.map(x => [x * 2]);
// [[2], [4], [6], [8]]
arr1.flatMap(x => [x * 2]);
// [2, 4, 6, 8]
// only one level is flattened
arr1.flatMap(x => [[x * 2]]);
// [[2], [4], [6], [8]]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin
arr.copyWithin(target)
arr.copyWithin(target, start)
arr.copyWithin(target, start, end)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
arr.fill(value[, start[, end]])
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
new
const data = {
"name": "test",
"pro_type": "Base",
"src_path": "xxx",
"release_path": "xxx",
"svn_user": "xyz",
"org.gil.server.report": "on",
"Robots": "on"
};
let keys = Object.keys(data);
const new_result = keys.filter(key => (data[key] === "on"));
// (2) ["org.gil.server.report", "Robots"]
// let result = [];
// for (let i = 0; i < keys.length; i++) {
// if (data[keys[i]] === "on") {
// result.push(keys[i]);
// }
// }
// result;
// (2) ["org.gil.server.report", "Robots"]
old
const data = {
"name": "test",
"pro_type": "Base",
"src_path": "xxx",
"release_path": "xxx",
"svn_user": "xyz",
"org.gil.server.report": "on",
"Robots": "on"
};
undefined
let keys = Object.keys(data);
// undefined
let result = [];
for (let i = 0; i < keys.length; i++) {
if (data[keys[i]] !== "on") {
result.push(keys[i]);
}
}
// undefined
keys;
// (7) ["name", "pro_type", "src_path", "release_path", "svn_user", "org.gil.server.report", "Robots"]
result
// (5) ["name", "pro_type", "src_path", "release_path", "svn_user"]
result = [];
for (let i = 0; i < keys.length; i++) {
if (data[keys[i]] === "on") {
result.push(keys[i]);
}
}
// 2
result;
// (2) ["org.gil.server.report", "Robots"]
splice()
+ indexOf()
=== filter()
How do I remove a particular element from an array in JavaScript?
https://stackoverflow.com/questions/369602/php-delete-an-element-from-an-array http://fellowtuts.com/php/delete-element-by-value-from-array-not-by-key/ https://stackoverflow.com/questions/1672156/how-to-delete-an-array-element-based-on-key https://coderanch.com/t/454700/java/Proper-remove-shift-elements-array
performance optimization 性能优化
<link rel="preload" href="/static/js/app.f0740e69f6377b5e784f.js" as="script">
<link rel="preload" href="/static/js/14.3d579fef7bcc5b20c2cc.js" as="script">
<link rel="preload" href="/static/css/app.d3668b3b356b3a7a2ff319b33312d3b2.css" as="style">
<link rel="prefetch" href="/static/js/12.cbf64669f2914491841d.js">
<!DOCTYPE html>
<html lang="en-us" manifest="manifest.appcache">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0">
<title>xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!</title>
<link rel="icon" href="images/logo.png" type="image/png">
<link rel="icon" href="./favicon.ico" type="image/x-icon">
<!-- SEO meta -->
<link rel="author" type="text/plain" href="https://www.xgqfrms.xyz/humans.txt" />
<link rel="manifest" href="manifest.json">
<link rel="shortlink" href="https://xgqfrms.xyz/">
<link rel="copyright" href="https://xgqfrms.xyz/copyright.html">
<!-- 预呈现和预提取支持:https://msdn.microsoft.com/library/dn265039(v=vs.85).aspx -->
<!--
<link rel="prerender" href="https://www.webgeeker.xyz/index.html" />
<link rel="prefetch" href="https://www.webgeeker.xyz/css/style.css" />
<link rel="dns-prefetch" href="https://www.webgeeker.xyz/" />
-->
<!-- Content Security Policy:内容安全策略(CSP) -->
<!--
<meta http-equiv="Content-Security-Policy" content="script-src 'self'; object-src 'none'; style-src 'cdn.xgqfrms.xyz'; child-src 'https: https:'">
-->
<!--
https://realfavicongenerator.net/
https://css-tricks.com/favicon-quiz/
-->
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00ff00">
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="msapplication-TileImage" content="/mstile-144x144.png">
<meta name="theme-color" content="#00ccff">
<!-- HEAD -->
<!-- <meta name="robots" content="noindex" /> -->
<meta name="author" content="xgqfrms, webgeeker">
<meta name="keywords" content="xgqfrms, webgeeker, github, xgqfrms.xyz, webgeeker.xyz, Tutorials, ES5 ES6 ES7, React 2, Angular 2, Ionic 2">
<meta name="description" content="xgqfrms.xyz : xgqfrms's offical website of GitHub! & xgqfrms, webgeeker, github, xgqfrms.xyz, webgeeker.xyz, Tutorials, ES5 ES6 ES7, React 2, Angular 2, Ionic 2">
<meta name="application-name" content="xgqfrms.xyz, webgeeker.xyz">
<meta name="generator" content="Sublime Text 3, Visual Studio Code 1.6, Google Chrome Canary, GitHub, React 2, Angular 2, Ionic 2">
<meta name="msapplication-TileColor" content="#00ff00" />
<!-- media query -->
<!-- RSS -->
<link href="https://xgqfrms.xyz/feeds/posts.rss" type="application/rss+xml" rel="alternate" title="Blog RSS" />
<link href="https://xgqfrms.xyz/feeds/atom.xml" type="application/atom+xml" rel="alternate" title="Atom Feed" />
</head>
https://stackoverflow.com/questions/5376444/how-do-i-disable-a-href-link-in-javascript
.btn-disabled {
cursor: not-allowed !important;
pointer-events: none;
}
// Select a node on click
publishBtn.addEventListener(`click`, (e) => {
let apisName = [...apinamesSet];
console.log(`publish apisName = \n`, JSON.stringify(apisName, null, 4));
// once
e.target.setAttribute("disabled", true);
e.target.classList.add("btn-disabled");
e.target.href = "javascript:void(0)";
e.preventDefault();
publisProject(apisName);
});
https://caniuse.com/#feat=pointer-events
https://stackoverflow.com/questions/28318057/html-how-to-disable-a-href
https://www.w3schools.com/jsref/met_win_setinterval.asp
https://stackoverflow.com/questions/729921/settimeout-or-setinterval
// 5s & interval
let timeUid = setInterval(() => {
if (istrue) {
getDatas(`http://10.1.5.202/deploy-platform/mock-json/progress.json`).then(
(json) => {
// console.log(`json =`, json);
window.message = json.data.message;
// show message
}
).catch(err => console.log(`error = `, err));
} else {
clearInterval(timeUid);
}
}, 5000);
demo
https://jsfiddle.net/GustvandeWal/295jqqqb/
https://www.w3schools.com/jsref/met_win_settimeout.asp https://www.w3schools.com/jsref/met_win_cleartimeout.asp
ecmaFeatures.experimentalObjectRestSpread
ecmaVersion: 2018
https://eslint.org/docs/user-guide/configuring
https://github.com/tc39/proposal-object-rest-spread https://babeljs.io/docs/plugins/transform-object-rest-spread/
.eslintrc
{
"env": {
"browser": true,
"node": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true,
"experimentalObjectRestSpread": true
}
},
"plugins": [
"react"
],
"extends": ["eslint:recommended", "plugin:react/recommended"],
"rules": {
"comma-dangle": 0,
"react/jsx-uses-vars": 1,
"react/display-name": 1,
"react/prop-types": 1,
"no-unused-vars": "warn",
"no-console": 1,
"no-unexpected-multiline": "warn"
},
"settings": {
"react": {
"pragma": "React",
"version": "15.6.1"
}
},
"globals": {
"window": true,
"jquery": true,
"xyz": false
}
}
oncopy="return false" onpaste="return false"
<input type="password" name="password" ng-model="password" required="" md-maxlength="20" oncopy="return false" onpaste="return false" class="md-input ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-valid-md-maxlength ng-touched" id="input_4" aria-invalid="false" ng-trim="false" style="">
https://www.w3schools.com/tags/tag_colgroup.asp
https://www.w3schools.com/tags/att_colgroup_width.asp
https://html.com/tags/colgroup/
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup
<section>
<table class="gildata-table">
<colgroup>
<col width="10%" span="2">
<col width="30%">
<col width="50%">
</colgroup>
<thead class="gildata-thead">
<tr class="gildata-tr">
<th colspan="2">long long long 表头 1</th>
<th rowspan="2">表头 2</th>
<th rowspan="2">表头 3</th>
</tr>
<tr class="gildata-tr">
<th>多级表头 1</th>
<th>多级表头 2</th>
</tr>
</thead>
</table>
</section>
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
// test
let str1 = `基金 专题 资产配置 其他 组合重大变动明细`,
str2 = `基金,专题,资产配置,其他,组合重大变动明细`,
str3 = `基金, 专题, 资产配置, 其他, 组合重大变动明细`,
str4 = `基金 ,专题 ,资产配置 ,其他 ,组合重大变动明细`,
str5 = `基金 , 专题 , 资产配置 , 其他 , 组合重大变动明细`,
str6 = ` , 基金 , 专题 , 资产配置 , 其他 , 组合重大变动明细 , `;
const stringToArray = (str = ``) => {
let result = [];
result = str.replace(/,/ig, " ").trim().replace(/\s+/ig, ",").split(",");
return result;
};
stringToArray(str6);
// (5) ["基金", "专题", "资产配置", "其他", "组合重大变动明细"]
http://troubleshooter.xyz/wiki/fix-err-connection-timed-out-issue-in-google-chrome/
const json = {
"keys": ["aaa","bbb"],
"data": {
"aaa": [
{
"date": "2018-05-04 06:59:48",
"auther": "xxx",
"jiraId": null,
"message": "test部署平台拉取日志 1"
},
{
"date": "2018-05-04 06:59:48",
"auther": "zzz",
"jiraId": null,
"message": "test部署平台拉取日志 2"
}
],
"bbb": [
{
"date": "2018-05-04 06:59:48",
"auther": "vvv",
"jiraId": null,
"message": "logs 日志"
}
]
}
};
let keys = json.keys,
data = json.data;
let bd = document.querySelector(`body`);
bd.innerHTML = "";
for (let i = 0; i < keys.length; i++) {
messages = data[keys[i]];
messages.forEach(obj => {
let {
date,
auther,
jiraId,
message
} = {...obj};
let str = `
${jiraId ? jiraId : ""}: ${message ? message.replace(/\n/ig, "<br/>") : ""}<br/>
`;
bd.insertAdjacentHTML(`beforeend`, str);
// return str;
});
}
https://codepen.io/xgqfrms-gildata/pen/zjdzap
http://imaputz.com/cssStuff/bigFourVersion.html
http://salzerdesign.com/test/fixedTable.html
http://maxdesign.com.au/jobs/sample-fixed-thead/index.htm
https://www.cssscript.com/fix-table-header-column/ https://www.cssscript.com/demo/fix-table-header-column/ https://www.cssscript.com/demo/fix-table-header-column/fixed-table.css https://www.cssscript.com/demo/fix-table-header-column/fixed-table.js
https://codepen.io/xgqfrms-gildata/pen/ELvwvV
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS: fixed table header</title>
<style>
table {
width: 100%;
border-collapse: collapse;
overflow: auto;
}
thead {
display: block;
width: 100%;
overflow: auto;
color: #fff;
background: #000;
max-width: 500px;
}
tbody {
display: block;
width: 100%;
height: 200px;
background: pink;
overflow: auto;
max-width: 500px;
}
th,
td {
padding: .5em 1em;
text-align: left;
vertical-align: top;
}
th:nth-of-type(n + 1),
td:nth-of-type(n + 1) {
border-left: 1px solid #fff;
}
tr:nth-of-type(n + 1) {
border-bottom: 1px solid #fff;
}
tbody tr:hover {
cursor: pointer;
background: rgb(247, 3, 44);
}
th:nth-of-type(1),
td:nth-of-type(1) {
width: 200px;
min-width: 200px;
}
th:nth-last-of-type(1),
td:nth-last-of-type(1) {
width: 400px;
min-width: 200px;
}
.col {
width: 300px;
}
</style>
</head>
<body>
<section>
<table>
<colgroup>
<col class="col">
<col class="col">
</colgroup>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
</table>
</section>
<section>
<table>
<colgroup>
<col class="col">
<col class="col">
</colgroup>
<tbody>
<tr>
<td>Cell 1, Row 1</td>
<td>Cell 2, Row 1</td>
</tr>
<tr>
<td>Cell 1, Row 2</td>
<td>Cell 2, Row 2</td>
</tr>
<tr>
<td>Cell 1, Row 3</td>
<td>Cell 2, Row 3</td>
</tr>
<tr>
<td>Cell 1, Row 4</td>
<td>Cell 2, Row 4</td>
</tr>
<tr>
<td>Cell 1, Row 5</td>
<td>Cell 2, Row 5</td>
</tr>
<tr>
<td>Cell 1, Row 6</td>
<td>Cell 2, Row 6</td>
</tr>
<tr>
<td>Cell 1, Row 7</td>
<td>Cell 2, Row 7</td>
</tr>
<tr>
<td>Cell 1, Row 8</td>
<td>Cell 2, Row 8</td>
</tr>
<tr>
<td>Cell 1, Row 9</td>
<td>Cell 2, Row 9</td>
</tr>
<tr>
<td>Cell 1, Row 10</td>
<td>Cell 2, Row 10</td>
</tr>
<tr>
<td>Cell 1, Row 11</td>
<td>Cell 2, Row 11</td>
</tr>
<tr>
<td>Cell 1, Row 12</td>
<td>Cell 2, Row 12</td>
</tr>
</tbody>
</table>
</section>
<!-- js -->
<script>
let trs = [...document.querySelectorAll(`tbody tr`)];
trs.forEach((tr) => {
tr.addEventListener(`click`, (e) => {
console.log(`e =\n`, e);
// td / cell
// console.log(`e.target.innerHTML =\n`, e.target.innerHTML);
// tr
// console.log(`e.target.parentNode =\n`, e.target.parentNode);
// console.log(`e.target.parentNode.children =\n`, e.target.parentNode.children);
// console.log(`e.target.parentElement.Text =\n`, e.target.parentElement.innerText);
let tds = [...e.target.parentNode.children],
result = [];
for (let i = 0; i < tds.length; i++) {
let value = tds[i].innerText;
result.push(value);
}
// get Row Datas
console.log(`result =\n`, result);
window.ROW = [];
window.ROW = result;
return result;
});
});
</script>
</body>
</html>
no
for
& create Array 100Uint8Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
https://en.wikipedia.org/wiki/Bit_array
https://stackoverflow.com/questions/29523206/how-do-i-write-an-8-bit-array-to-a-16-bit-array-of-1-2-size https://stackoverflow.com/questions/33793246/c-converting-8-bit-values-into-16-bit-values
Typed Arrays
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array