Skip to content

Instantly share code, notes, and snippets.

Avatar

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

View GitHub Profile
@termi
termi / event_delegation.js
Created Apr 12, 2012
event delegation. It is nearly 140 bytes but unsafe. For more complex solution see comments
View event_delegation.js
function(
a, //CSS selector
b //callback function
) {
return function(
e, // event
c, // (placeholder)
d // (placeholder)
) {
d = e.target;
@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 / LICENSE.txt
Created May 1, 2012 — forked from 140bytes/LICENSE.txt
event delegation
View LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@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 / bug_examples.html
Created Aug 30, 2012
Fix Safari bug with [radio input with no form].cloneNode()
View bug_examples.html
<html>
<form>
<div id="test3">
test1 :
<input id="test1" type="radio" name="test" checked />
</div>
test 2:
<input type="radio" name="test" />
</form>
@termi
termi / polyfill.js
Created Sep 18, 2012 — forked from Raynos/polyfill.js
RadioNodeList polyfill
View polyfill.js
/*
demo :- http://jsfiddle.net/termi/pyFXW/
Implements RadioNodeList :- http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#radionodelist
Implementation just adds `.value` as a property to `NodeList`.
Requires ES5 shim and ES5 shimmable browser. (Modern and IE8)
*/
;(function () {
@termi
termi / index.js
Created Sep 25, 2012
:scope support test
View index.js
function testForRealScopePreudoClassSupport() {
var scopeSupport = false
, tmp = document.createElement("b")
;
tmp.innerHTML = "<i>t</i>";
try {
scopeSupport = tmp.querySelector(":scope>i");
scopeSupport = scopeSupport && scopeSupport.innerHTML == "t";
@termi
termi / index.js
Created Oct 25, 2012
New DOM4 classList polyfill for browsers with classList support
View index.js
void function(global, tmp) {
if("classList" in tmp) {
void function(_add, _remove, _Array_forEach_) {
this["add"] = function() {
_Array_forEach_.call(arguments, _add, this);
};
this["remove"] = function() {
_Array_forEach_.call(arguments, _remove, this);
};
this["toggle"] = function(token, forse) {
@termi
termi / index.js
Created Nov 1, 2012
getElementsByClassName-like function for all browsers (IE6+ / w3c)
View index.js
var
/** @type {RegExp} @const */
RE__getElementsByClassName = /\s*(\S+)\s*/g
/** @type {string} @const */
, STRING_FOR_RE__getElementsByClassName = '(?=(^|.*\\s)$1(\\s|$))'
/** @type {boolean} @const */
, IS_IELT9 = !/\[native\s+code\]/i.test(document.getElementsByClass + "")
/** @type {RegExp} @const */
, RE__querySelector__dottes = /\./g
;
@termi
termi / index.js
Created Nov 6, 2012
Add/Remove listeners
View index.js
void function(exports) {
var _browser_msie = window["eval"] && window["eval"]("/*@cc_on 1;@*/") && +((/msie (\d+)/i.exec(navigator.userAgent) || [])[1] || 0) || void 0
, _document_documentElement = document.documentElement
, _document_body = document.body
, _append = function(obj, extention) {
for(var key in extention)