Skip to content

Instantly share code, notes, and snippets.

View andreiglingeanu's full-sized avatar

Andrei Glingeanu andreiglingeanu

View GitHub Profile

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@andreiglingeanu
andreiglingeanu / events.js
Last active December 13, 2015 20:08
pure javascript event utility - a mini-framework for less use of events in js.
var eventUtility = {
addEvent : (function() {
if (typeof addEventListener !== "undefined") {
return function(obj, evt, fn) {
obj.addEventListener(evt, fn, false);
};
} else {
return function(obj, evt, fn) {
obj.attachEvent("on" + evt, fn);
};
@andreiglingeanu
andreiglingeanu / class.js
Created February 17, 2013 16:14
javascript class utility
function addClass(el, cls) {
var c = el.className.split(' ');
for (var i=0; i<c.length; i++) {
if (c[i] == cls) return;
}
c.push(cls);
el.className = c.join(' ');
}
function removeClass(el, cls) {
@andreiglingeanu
andreiglingeanu / getComputedStyle.js
Last active December 13, 2015 20:48
getComputedStyle for IE
function getIEComputedStyle(elem, prop) {
var value = elem.currentStyle[prop] || 0
// we use 'left' property as a place holder so backup values
var leftCopy = elem.style.left
var runtimeLeftCopy = elem.runtimeStyle.left
// assign to runtimeStyle and get pixel value
elem.runtimeStyle.left = elem.currentStyle.left
elem.style.left = (prop === "fontSize") ? "1em" : value
@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;
}