Skip to content

Instantly share code, notes, and snippets.

View englishextra's full-sized avatar
💜
the beat goes on

englishextra englishextra

💜
the beat goes on
View GitHub Profile
@chrisjlee
chrisjlee / querySelector.polyfill.js
Created February 12, 2014 17:39
IE document.querySelector() polyfill
if (!document.querySelectorAll) {
document.querySelectorAll = function (selectors) {
var style = document.createElement('style'), elements = [], element;
document.documentElement.firstChild.appendChild(style);
document._qsa = [];
style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
window.scrollBy(0, 0);
style.parentNode.removeChild(style);
@cvan
cvan / delegate.js
Created February 4, 2014 05:33
simple querySelectorAll wrapper + event delegation
function $(sel) {
if (!sel) {
return document.body;
}
var r = document.querySelectorAll(sel);
return r.length == 1 ? r[0] : Array.prototype.slice.call(r);
}
$.matches = function(el, sel) {
var matchesSelector = el.webkitMatchesSelector || el.mozMatchesSelector ||
@kkga
kkga / plain.js
Last active March 1, 2022 16:05
snippets of plain js
// document.ready
document.addEventListener("DOMContentLoaded", function() {
// your code
}, false);
// select div
var element = document.querySelector("div");
@bartholomej
bartholomej / css-media-queries-cheat-sheet.css
Last active May 11, 2024 22:07
CSS Media Query Cheat Sheet (with Foundation)
/*------------------------------------------
Responsive Grid Media Queries - 1280, 1024, 768, 480
1280-1024 - desktop (default grid)
1024-768 - tablet landscape
768-480 - tablet
480-less - phone landscape & smaller
--------------------------------------------*/
@media all and (min-width: 1024px) and (max-width: 1280px) { }
@media all and (min-width: 768px) and (max-width: 1024px) { }
@dalgard
dalgard / queryAll.js
Created December 6, 2013 01:55
Efficient wrapper for document.querySelectorAll
// Always return an array of DOM elements
function queryAll(selector) {
var id_sel = selector.match(/^#([\w-]*)$/),
class_sel = !id_sel && selector.match(/^\.([\w-]+)$/),
tag_sel = !class_sel && selector.match(/^[\w-]+$/);
if (id_sel) {
var elem = document.getElementById(id_sel[1]);
return (elem ? [elem] : []); // Always return an array
}
@xeoncross
xeoncross / ajax.js
Last active August 3, 2023 06:06
Simple, cross-browser Javascript POST/GET xhr request object. Supports request data and proper AJAX headers.
/**
* IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
*
* @param string url
* @param object callback
* @param mixed data
* @param null x
*/
function ajax(url, callback, data, x) {
try {
@chriswrightdesign
chriswrightdesign / ie8Events.js
Created November 20, 2013 23:47
Polyfill for IE8 Javascript Event Listeners
(function() {
if (!Event.prototype.preventDefault) {
Event.prototype.preventDefault=function() {
this.returnValue=false;
};
}
if (!Event.prototype.stopPropagation) {
Event.prototype.stopPropagation=function() {
this.cancelBubble=true;
};
@erikroyall
erikroyall / evento.js
Last active September 23, 2016 17:03
A cross-browser event handling system
// Evento - v1.0.0
// by Erik Royall <erikroyalL@hotmail.com> (http://erikroyall.github.io)
// Dual licensed under MIT and GPL
// Array.prototype.indexOf shim
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
'use strict';
@ingdir
ingdir / gist:0b211b9253c376f9cfa5
Last active December 3, 2023 11:47
BEM Cheatsheet

BEM Cheatsheet

BLOCK

Block encapsulates a standalone entity that is meaningful on its own.

While blocks can be nested and interact with each other, semantically they remain equal; there is no precedence or hierarchy.

Holistic entities without DOM representation (such as controllers or models) can be blocks as well.

@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.