Skip to content

Instantly share code, notes, and snippets.

Avatar

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

View GitHub Profile
@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
@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 / build.js
Created Nov 19, 2012
JS GCC compile or remove GCC globals
View build.js
#!/usr/bin/env node
if (process.argv.length < 3) {
console.error('No enough parameters');
process.exit();
}
const fs = require('fs')
, path = require('path')
;
@termi
termi / index.js
Created Nov 7, 2012
offset[Left/Top]
View index.js
var getScrollX
, getScrollX
, _document_documentElement = document.documentElement
;
document.compatMode === "CSS1Compat" ?
((_getScrollX = function(){return _document_documentElement.scrollLeft}), (_getScrollY = function(){return _document_documentElement.scrollTop}))
:
((_getScrollX = function(){return document.body.scrollTop}), (_getScrollY = function(){return document.body.scrollLeft}))
;
@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)
@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 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 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 / 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 () {