Skip to content

Instantly share code, notes, and snippets.

View chekit's full-sized avatar
👋

Anton Cherepov chekit

👋
View GitHub Profile
@chekit
chekit / server.js
Last active August 29, 2015 14:17 — forked from alexesDev/server.js
var express = require('express');
var app = express();
function productCount(){
return Math.round(Math.random() * 10 + 1);
}
function times(n, callback){
var list = [];
@chekit
chekit / README.md
Last active August 29, 2015 14:22 — forked from jonathantneal/README.md

EventListener Polyfill

Is IE8 your new IE6? Level the playing field with polyfills.

This script polyfills addEventListener, removeEventListener, and dispatchEvent. It is less than half a kilobyte minified and gzipped.

addEventListener

addEventListener registers a single event listener on a single target.

@chekit
chekit / stop-typing-detection.md
Last active August 29, 2015 14:22
How to detect if user stops typing

So, I'm going to guess finish typing means you just stop for a while, say 5 seconds. So with that in mind, lets start a timer when the user releases a key and clear it when they press one. I decided the input in question will be #myInput.

Making a few assumptions...

//setup before functions
var typingTimer;                //timer identifier
var doneTypingInterval = 5000;  //time in ms, 5 second for example

//on keyup, start the countdown
@chekit
chekit / trim-to-string.md
Created June 9, 2015 13:05
Add trim() method to String.prototype

Add the following code to add trim functionality to the string.

if ( typeof String.prototype.trim !== 'function' ) {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}
@chekit
chekit / disable-back-btn.js
Last active August 29, 2015 14:26
Disable Back button on Browser and Android Hardware
(function (w) {
'use strict';
w.location.hash = "no-back-button";
w.location.hash = "Again-No-back-button";//again because google chrome don't insert first hash into history
w.onhashchange = function(){
w.location.hash = "no-back-button";
}
@chekit
chekit / HideMobileAddressBar.js
Last active October 27, 2015 22:21 — forked from mhammonds/HideMobileAddressBar.js
Hide Browser Address Bar - Android + iPhone
//На одном из проектов оказалось, что достаточно добавить body position:fixed
//Ситуация была: на мобильных меню при открытии становилось fixed, но при прокрутке снизу из-за адресной строки появлялся "провал"
//Так же для манипуляции меню к body добавлялся класс .show-nav
//В моей ситуации оказалось достаточно просто добавить в show-nav position: fixed (пофиксить body)
function hideAddressBar()
{
if(!window.location.hash)
{
if(document.height < window.outerHeight)
@chekit
chekit / modernizr.positionfixed.js
Created October 29, 2015 08:54 — forked from bobslaede/modernizr.positionfixed.js
Modernizr position fixed check
;(function(Modernizr, window) {
Modernizr.addTest('positionfixed', function () {
var test = document.createElement('div'),
control = test.cloneNode(false),
fake = false,
root = document.body || (function () {
fake = true;
return document.documentElement.appendChild(document.createElement('body'));
}());
@chekit
chekit / hidekeyboard.js
Created November 24, 2015 22:23
Hide Native Keyboard On iPhone
//Задача: убирать нативную клавиатуру после ввода параметра в поле поиска и выдачи результатов
//Данную функцию вызывать на 'success' выполнения запроса
var hideKeyboard = function() {
document.activeElement.blur();
$("input").blur();
};
//Страница с вопросом: http://stackoverflow.com/questions/5937339/ipad-safari-make-keyboard-disappear
@chekit
chekit / in-viewport.js
Created January 14, 2016 14:43
Detect if element inside viewport or not
function elementInViewport (el) {
var top = el.offsetTop;
var left = el.offsetLeft;
var width = el.offsetWidth;
var height = el.offsetHeight;
while(el.offsetParent) {
el = el.offsetParent;
top += el.offsetTop;
left += el.offsetLeft;
@chekit
chekit / promise-sequence.js
Last active May 23, 2016 17:47
Gets an array values consistently, read them and resolve with results (this is a basic example that was done to understand how I can read array, make an ajax call with value and resolve for getting next one). The values are printing in arow.
'use strict';
//The sandbox http://jsbin.com/leraku/edit?js,console
let mas = [1, 2, 3];
let prom = function (value) {
return new Promise(resolve => {
setTimeout(() => {
console.log(value);