Skip to content

Instantly share code, notes, and snippets.

View termi's full-sized avatar

Егор Халимоненко termi

View GitHub Profile
@termi
termi / scrollIntoView_polyfill.js
Last active March 6, 2019 15:22
Support centering an element when scrolling into view w3c issue: https://www.w3.org/Bugs/Public/show_bug.cgi?id=17152 Original code from http://jsbin.com/ilecok/16/
////////////////////////////////////////////////////////////////////////////////
// Author: Thaddee Tyl 2012.
// The following work is under CC0.
void function() {
// Hook the polyfill.
Element.prototype._scrollIntoView = function scrollIntoView(options) {
if( !this.ownerDocument )return;
@termi
termi / declension.js
Created October 21, 2013 09:55
Склонение существительных
/**
* Склонение существительных
* Правильная форма cуществительного рядом с числом (счетная форма).
*
* @example declension("файл", "файлов", "файла", 0);//returns "файлов"
* @example declension("файл", "файлов", "файла", 1);//returns "файл"
* @example declension("файл", "файлов", "файла", 2);//returns "файла"
*
* @param {string} oneNominative единственное число (именительный падеж)
* @param {string} severalGenitive множественное число (родительный падеж)
@termi
termi / matchesSelector_shim.js
Last active February 9, 2021 09:52
Element.prototype.matchesSelector shim
var _hasOwnProperty = Object.prototype.hasOwnProperty;
if(!Element.prototype.matchesSelector) {
Element.prototype.matchesSelector =
Element.prototype.matches ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector || function(selector) {
if(!selector)return false;
@termi
termi / crossBrowser_initKeyboardEvent.js
Last active June 13, 2023 02:01
Cross-browser initKeyboardEvent
void function() {//closure
var global = this
, _initKeyboardEvent_type = (function( e ) {
try {
e.initKeyboardEvent(
"keyup" // in DOMString typeArg
, false // in boolean canBubbleArg
, false // in boolean cancelableArg
, global // in views::AbstractView viewArg
@termi
termi / Symbol_test.js
Created March 3, 2014 13:04
Symbol's polyfill test
applyPolyfills();var $S_polyfill$0 = Symbol["__polyfill__"];var $S_SET$0, $S_GET$0, $isSymbol$0;if($S_polyfill$0){$S_SET$0 = $S_polyfill$0["__setObjectSetter__"];$S_GET$0 = $S_polyfill$0["__setObjectGetter__"];$isSymbol$0 = $S_polyfill$0["__isSymbol__"];$S_polyfill$0 = true;}else {$S_polyfill$0 = false}
var private1 = Symbol();var $S$0 = $S_polyfill$0 && typeof private1 === 'object' && $isSymbol$0(private1);
var private2 = Symbol();var $S$1 = $S_polyfill$0 && typeof private2 === 'object' && $isSymbol$0(private2);
var publicProp1 = 'public_prop1';
var publicProp2 = (function(){return 'public_prop1'})();var $S$2 = $S_polyfill$0 && typeof publicProp2 === 'object' && $isSymbol$0(publicProp2);
function createSymbolOrObject(createSymbol){ return createSymbol ? Symbol() : {} };
{// simple
var obj = {}, obj1 = {};