Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrei Glingeanu andreiglingeanu

View GitHub Profile
View gist:4597646

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 Dec 13, 2015
pure javascript event utility - a mini-framework for less use of events in js.
View events.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 Feb 17, 2013
javascript class utility
View class.js
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 Dec 13, 2015
getComputedStyle for IE
View getComputedStyle.js
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 Dec 13, 2015
get object that contains attributes of an element
View outputAttributes.js
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 Feb 23, 2013
ie6 hover for any element.
View ie6_hover.css
* html body {
/* IE6 behavior must be in HEAD */
/* http://www.xs4all.nl/~peterned/csshover.html */
behavior:url("csshover.htc");
}
View isHidden.js
function isHidden(elem){
return !elem.offsetWidth && !elem.offsetHeight;
}
View fixPageXY.js
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);
View getCoords.js
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;
View fixEvent.js
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;
}