Skip to content

Instantly share code, notes, and snippets.

View andreiglingeanu's full-sized avatar

Andrei Glingeanu andreiglingeanu

View GitHub Profile
@andreiglingeanu
andreiglingeanu / outputAttributes.js
Last active December 13, 2015 21:38
get object that contains attributes of an element
function outputAttributes (element) {
var pairs = {},
attrName,
attrValue,
i,
len;
for ( i = 0, len = element.attributes.length; i < len; i++ ) {
attrName = element.attributes[i].nodeName;
attrValue = element.attributes[i].nodeValue;
@andreiglingeanu
andreiglingeanu / ie6_hover.css
Created February 23, 2013 09:52
ie6 hover for any element.
* html body {
/* IE6 behavior must be in HEAD */
/* http://www.xs4all.nl/~peterned/csshover.html */
behavior:url("csshover.htc");
}
@andreiglingeanu
andreiglingeanu / isHidden.js
Last active December 14, 2015 03:09
isHidden
function isHidden(elem){
return !elem.offsetWidth && !elem.offsetHeight;
}
@andreiglingeanu
andreiglingeanu / fixPageXY.js
Last active December 14, 2015 03:48
fix pageX/pageY
function fixEvent(e) {
e = e || window.event;
if (!e.target) e.target = e.srcElement;
if (e.pageX == null && e.clientX != null ) { // если нет pageX..
var html = document.documentElement;
var body = document.body;
e.pageX = e.clientX + (html.scrollLeft || body && body.scrollLeft || 0);
@andreiglingeanu
andreiglingeanu / getCoords.js
Created February 24, 2013 10:10
get element coords
function getCoords(elem) {
var box = elem.getBoundingClientRect();
var body = document.body;
var docEl = document.documentElement;
var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
var clientTop = docEl.clientTop || body.clientTop || 0;
@andreiglingeanu
andreiglingeanu / fixEvent.js
Created February 24, 2013 15:28
fix events
function fixEvent(e, _this) {
e = e || window.event;
if (!e.currentTarget) e.currentTarget = _this;
if (!e.target) e.target = e.srcElement;
if (!e.relatedTarget) {
if (e.type == 'mouseover') e.relatedTarget = e.fromElement;
if (e.type == 'mouseout') e.relatedTarget = e.toElement;
}
@andreiglingeanu
andreiglingeanu / animate.js
Created February 25, 2013 16:17
javascript animate utility
/**
Docs: http://learn.javascript.ru/tutorial/lib
*/
/**
* Анимация. Параметры:
* opts.delta(time) -- временная функция, time=0..1. По умолчанию linear.
* opts.step(progress) -- функция рисования, progress=0..1.
* opts.complete -- функция, которая выполнится по окончании анимации
* opts.delay -- задержка между кадрами, по умолчанию 13
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.cf:before,
@andreiglingeanu
andreiglingeanu / inheritance.js
Created March 31, 2013 13:07
Function.prototype.method Function.prototype.inherits Function.prototype.swiss
Function.prototype.method = function ( name, func ) {
this.prototype[name] = func;
return this;
};
Function.method('inherits', function ( parent ) {
var depth = 0;
var proto = this.prototype = new parent();
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))