const fs = require('fs');
const path = require('path');
let pathSupplied = './';
let extFilter = 'js';
let extension = (element) => {
let extName = path.extname(element);
return extName === '.' + extFilter;
};
let walk = function (dir) {
const result = [];
fs.readdir(dir, function (err, list) {
list.forEach((item) => {
let itemPath = path.join(dir, item);
fs.stat(itemPath, (e, stats) => {
if (stats.isDirectory()) {
walk(itemPath);
} else {
if(extension(itemPath)){
console.log(itemPath)
result.push(itemPath);
}
}
});
});
});
return result;
}
walk(pathSupplied);
walkAsync = (dir)=>{
return new Promise((resolve)=>{
resolve(walk(dir))
});
}
nextSlideHandler = (e, item, index ) => {
let arr = [...this.state.data];
const {direction} = e.currentTarget.dataset;
const {currentImageIndex,
images} = this.state.data[index];
const newIndex = direction === 'next'
? (currentImageIndex+1) % (images.length-1)
: ((currentImageIndex || images.length)-1) % (images.length-1);
arr[index].cantGoNext = true;
arr[index].cantGoPrev = newIndex !== 0;
arr[index].currentImageIndex = newIndex;
this.setState({ data:arr });
}
case '/data.json':
const js = fs.readFileSync('data.json', 'utf8');
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(js);
// https://stackoverflow.com/questions/3916191/download-data-url-file/45905238#45905238?newreg=ddb3c48865d04c319b39f772df762521
function download(dataurl, filename) {
var a = document.createElement("a");
a.href = dataurl;
a.setAttribute("download", filename);
a.click();
}
#someform:invalid [type=submit]{
pointer-events: none;
/* другие нужные стили, да хоть display: none; */
}
class Point {
constructor(x, y, ...other) {
if(other.length > 0){
throw 'Only 2 number arguments';
}
if(typeof x !== 'number'){
throw TypeError(`The first argument must be number but have got ${typeof x}`);
}
if(typeof y !== 'number'){
throw TypeError(`The second argument must be number but have got ${typeof y}`);
}
this.x = x;
this.y = y;
}
}