Skip to content

Instantly share code, notes, and snippets.

Avatar

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

View GitHub Profile
@termi
termi / crossBrowser_initKeyboardEvent.js
Last active Aug 15, 2021
Cross-browser initKeyboardEvent
View crossBrowser_initKeyboardEvent.js
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 / matchesSelector_shim.js
Last active Feb 9, 2021
Element.prototype.matchesSelector shim
View matchesSelector_shim.js
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 / declension.js
Created Oct 21, 2013
Склонение существительных
View declension.js
/**
* Склонение существительных
* Правильная форма cуществительного рядом с числом (счетная форма).
*
* @example declension("файл", "файлов", "файла", 0);//returns "файлов"
* @example declension("файл", "файлов", "файла", 1);//returns "файл"
* @example declension("файл", "файлов", "файла", 2);//returns "файла"
*
* @param {string} oneNominative единственное число (именительный падеж)
* @param {string} severalGenitive множественное число (родительный падеж)
@termi
termi / scrollIntoView_polyfill.js
Last active Mar 6, 2019
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/
View scrollIntoView_polyfill.js
////////////////////////////////////////////////////////////////////////////////
// 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 / css3SelectorsPolyfill.js
Created May 5, 2012
getElementsByClassName/querySelector/querySelectorAll/matchesSelector Polyfill
View css3SelectorsPolyfill.js
/** @license MIT License (c) copyright Egor Halimonenko (termi1uc1@gmail.com) */
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @warning_level VERBOSE
// @jscomp_warning missingProperties
// @output_file_name a.js.querySelector.min.js
// @check_types
// ==/ClosureCompiler==
@termi
termi / findMicrodataProperties.js
Last active Dec 20, 2015
Find Microdata properties Note: Without itemref support
View findMicrodataProperties.js
function findMicrodataProperties(itemScopeNode, itemPropName) {
if( !itemScopeNode.hasAttribute("itemscope") ) {
return[];
}
var pending = []
, tmp
, currentNode
, k = -1
, el
@termi
termi / CSS.supports.js
Last active Dec 17, 2015
CSS.supports
View CSS.supports.js
/** github.com/termi/CSS.supports */
if( !global.CSS || !global.CSS.supports ) {
if( !global.CSS ) {
/**
* @expose
*/
global.CSS = {};
}
if( !global.CSS.supports && global["supportsCSS"] ) {// Opera 12.10 impl
View URL_polyfill.js
void function() {
"use strict";
var global = this;
//Mini alternative https://gist.github.com/2428561
//Uses
//https://gist.github.com/1384398
//https://gist.github.com/1235332
@termi
termi / index.js
Last active Dec 12, 2015
IE8 Array.prototype.splice.apply test
View index.js
(function() {
var _Array_slice_ = Array.prototype['slice'];
var _Array_splice_ = Array.prototype.splice;
if( Function.prototype.bind === void 0 ) Function.prototype.bind = function (context) {
var args = _Array_slice_.call(arguments, 1), self = this;
return function (){ return self.apply(context, args.concat(_Array_slice_.call(arguments, 0))); };
};
function makeArray(l) {
@termi
termi / IElt9_getComputedStyle.js
Last active Dec 12, 2015
getComputedStyle for IE < 9
View IElt9_getComputedStyle.js
void function() {
var global = this
/** @const */
, _Array_slice = Array.prototype.slice
/** @const */
, _Function_apply = Function.prototype.apply