Skip to content

Instantly share code, notes, and snippets.

function goTo(index) {
var dir = 1; // -1
var currentIndex = (dir * index + slidesLength) % slidesLength
}
@monochromer
monochromer / ValidationTest.js
Created July 28, 2016 08:47
Валидация данных
function ValidationTest(options) {
this.value = options.value;
this.rules = options.rules || [];
this.onSuccess = options.onSuccess;
this.onError = options.onError;
};
ValidationTest.prototype.destroy = function() {
this.value = null;
this.rules = null;
@monochromer
monochromer / media-mixin.styl
Last active June 28, 2019 21:07
Media Mixin for Styls
$media = {
medium: "(min-width: 992px)",
small: "(min-width: 768px)"
}
mq($mq)
if $mq in $media
$condition = $media[$mq]
else
$condition = $mq
@monochromer
monochromer / browser-sync-proxy.js
Last active July 5, 2017 08:06
browser-sync proxy
let browserSync = require('browser-sync').create();
browserSync.init({
proxy: 'http://site.com',
serveStatic: ['static'],
files: ['static/**/*.*'],
rewriteRules: [
{
match: /<\/head>/i,
fn: (req, res, match) => `<link rel="stylesheet" href="/custom.css" />`
@monochromer
monochromer / ui-bits.js
Last active April 26, 2019 23:47
Битовые маски в UI
/**
* Битовые маски в UI
* Автор: Игорь Алексеенко
*/
// состояния компонентов
class Button {
constructor() {
this.state =
@monochromer
monochromer / delegate.js
Created December 20, 2016 07:08
Делегироваие событий JavaScript
// http://codepen.io/32bitkid/post/understanding-delegated-javascript-events
var delegate = function(criteria, listener) {
return function(e) {
var el = e.target;
do {
if (!criteria(el)) continue;
e.delegateTarget = el;
listener.apply(this, arguments);
return;
@monochromer
monochromer / index.html
Last active March 18, 2021 17:17
progressive enhancement router
<!DOCTYPE html>
<html lang="en">
<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>History Test</title>
<style>
html {
font: 100%/1.5 sans-serif;
const applyMiddleware = (...middlewares) => store => {
if (middlewares.length === 0) {
return dispatch => dispatch;
}
if (middlewares.length === 1) {
return middlewares[0];
}
const boundMiddlewares = middlewares.map(middleware =>
middleware(store);
);
<!-- https://dassur.ma/things/lazyloading/ -->
<head>
<!-- ... -->
<noscript class="lazyload">
<link
rel="stylesheet"
href="/styles/things.css">
</noscript>
<!-- ... -->
// https://dassur.ma/things/raf-promise/
function transitionEndPromise(element, styles) {
return new Promise(resolve => {
element.addEventListener('transitionend', function f(event) {
if (event.target !== element) return;
element.removeEventListener('transitionend', f);
resolve();
});
Object.assign(element.style, styles);