JavaScript
4
Вклад в тег
import format from "date-fns/format";
import frLocale from "date-fns/locale/fr";
import ruLocale from "date-fns/locale/ru";
import enLocale from "date-fns/locale/en-US";
import DateFnsUtils from "@date-io/date-fns";
import MoreIcon from "@material-ui/icons/MoreVert";
import React, { useState, useCallback } from "react";
import { IconButton, Menu, MenuItem } from "@material-ui/core";
import { DatePicker, MuiPickersUtilsProvider } from "@material-ui/pickers";
const localeMap = {
en: enLocale,
fr: frLocale,
ru: ruLocale,
};
class RuLocalizedUtils extends DateFnsUtils {
getCalendarHeaderText(date) {
return format(date, "LLLL", { locale: this.locale });
}
getDatePickerHeaderText(date) {
return format(date, "dd MMMM", { locale: this.locale });
}
}
class FrLocalizedUtils extends DateFnsUtils {
getDatePickerHeaderText(date) {
return format(date, "d MMM yyyy", { locale: this.locale });
}
}
const localeUtilsMap = {
en: DateFnsUtils,
fr: FrLocalizedUtils,
ru: RuLocalizedUtils,
};
const localeFormatMap = {
en: "MMMM d, yyyy",
fr: "d MMM yyyy",
ru: "d MMM yyyy",
};
const localeCancelLabelMap = {
en: "cancel",
fr: "annuler",
ru: "отмена",
};
function DateFnsLocalizationExample() {
const [locale, setLocale] = useState("ru");
const [anchorEl, setAnchorEl] = useState(null);
const [selectedDate, handleDateChange] = useState(new Date());
const handleMenuOpen = useCallback(e => {
e.stopPropagation();
setAnchorEl(e.currentTarget);
}, []);
const selectLocale = useCallback(locale => {
setLocale(locale);
setAnchorEl(null);
}, []);
return (
<MuiPickersUtilsProvider utils={localeUtilsMap[locale]} locale={localeMap[locale]}>
<DatePicker
value={selectedDate}
onChange={handleDateChange}
format={localeFormatMap[locale]}
cancelLabel={localeCancelLabelMap[locale]}
InputProps={{
endAdornment: (
<IconButton
aria-label="Select locale"
onClick={handleMenuOpen}
aria-owns={anchorEl ? "locale-menu" : undefined}
>
<MoreIcon />
</IconButton>
),
}}
/>
<Menu
id="locale-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
>
{Object.keys(localeMap).map(localeItem => (
<MenuItem
key={localeItem}
selected={localeItem === locale}
onClick={() => selectLocale(localeItem)}
>
{localeItem}
</MenuItem>
))}
</Menu>
</MuiPickersUtilsProvider>
);
}
export default DateFnsLocalizationExample;
var doit;
function resizedw() {
if ($(document).width() < 500) {
$('.block').addClass("mobil");
$('.mobil').click(function() {
$(this).css('background', 'blue');
});
} else
$('.block').removeClass("mobil");
};
window.onresize = function() {
clearTimeout(doit);
doit = setTimeout(function() {
resizedw();
}, 0);
};
var cDiv = document.querySelector('button'),
el = document.getElementsByTagName('div');
var click = e => {
e = document.createElement('div');
e.setAttribute('class', 'sq');
document.body.appendChild(e);
el = e;
let elX = Math.floor(Math.random() * (151 - 50)) + 50;
let elY = Math.floor(Math.random() * (151 - 50)) + 50;
with(e.style) {
position = 'absolute';
width = elX + 'px';
height = elY + 'px';
background = '#f00';
zIndex = '-1';
border = '2px solid #000';
top = Math.floor(Math.random() * (window.innerHeight - elY)) + 'px';
left = Math.floor(Math.random() * (window.innerWidth - elX)) + 'px';
}
e.addEventListener('click', info);
};
var info = e => {
console.log(e.target);
};
cDiv.addEventListener('click', click);