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
@englishextra
englishextra / getChildrenByTags.js
Last active May 5, 2016 13:49
get children of a parent element by tag names
/*!
* get children of a parent element by tag nameS
* gist.github.com/englishextra/d4789c5d30f6f6b429fdf7aaebeda7b1
* based on quirksmode.org/dom/getElementsByTagNames.html
* takes two arguments:
* A string with a comma-separated list of tag names.
* An optional start element, otherwise document is used.
* var element = document.getElementById('test');
* var formFieldList = getElementsByTagNames('input,select,textarea',element);
*/
@englishextra
englishextra / getChildrenByTag.js
Last active May 7, 2016 14:10
get children of a parent element by tag name
/*!
* get children of a parent element by tag name
* no fallback to document if parent fail
* gist.github.com/englishextra/6d843e16c49cfde0a394bd9d76383b13
* jsfiddle.net/englishextra/c2vr5gxd/
* jsbin.com/xavocu/edit?html,js,output
*/
getChildrenByTag = (function (d, m) {
function g(t, p, o) {
o = Object.create(g.fn);
@englishextra
englishextra / querySelector.polyfill.js
Created May 6, 2016 18:53 — forked from chrisjlee/querySelector.polyfill.js
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);
@englishextra
englishextra / delegate.js
Created May 6, 2016 18:58 — forked from cvan/delegate.js
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 ||
@englishextra
englishextra / FX.js
Last active April 4, 2018 05:44
modified implementing fadeIn and fadeOut without jQuery
/*!
* implementing fadeIn and fadeOut without jQuery
* gist.github.com/englishextra/baaa687f6ae9c7733d560d3ec74815cd
* modified jsfiddle.net/LzX4s/
* changed options.complete(); to:
* function"==typeof options.complete && options.complete();
* usage:
* FX.fadeIn(document.getElementById('test'),
* {duration:2000,complete:function(){alert('Complete');}});
*/
@englishextra
englishextra / FadeOut.js
Last active May 9, 2016 15:44
FadeOut in pure JS
/*!
* Fade Out
* gist.github.com/englishextra/818ba5b558f9c15f9776684b8e8feaf9
* youmightnotneedjquery.com
* chrisbuttery.com/articles/fade-in-fade-out-with-javascript/
* fadeOut(el);
*/
function fadeOut(el){el.style.opacity=1;(function fade(){if((el.style.opacity-=.1)<0){el.style.display="none";}else{requestAnimationFrame(fade);}})();}
@englishextra
englishextra / FadeIn.js
Created May 9, 2016 15:38
FadeIn in pure JS
/*!
* Fade In
* gist.github.com/englishextra/cbf5137a95ed5e02927cd3e19e271bae
* youmightnotneedjquery.com
* fadeIn(el);
* fadeIn(el, "inline-block");
*/
function fadeIn(el){el.style.opacity=0;var last=+new Date();var tick=function(){el.style.opacity=+el.style.opacity+(new Date()-last)/400;last=+new Date();if(+el.style.opacity<1){(window.requestAnimationFrame&&requestAnimationFrame(tick))||setTimeout(tick,160);}};tick();}
@englishextra
englishextra / MediaHack.js
Last active October 9, 2016 20:28
modified MediaHack by Pomke Nohkan removed className fallback and additionally returns earlyDeviceOrientation,earlyDeviceSize
/*!
* modified MediaHack - (c) 2013 Pomke Nohkan MIT LICENCED.
* gist.github.com/englishextra/ff8c9dde94abe32a9d7c4a65e0f2ccac
* jsfiddle.net/englishextra/xg7ce8kc/
* removed className fallback and additionally
* returns earlyDeviceOrientation,earlyDeviceSize
* Add media query classes to DOM nodes
* github.com/pomke/mediahack/blob/master/mediahack.js
*/
var earlyDeviceOrientation = "", earlyDeviceSize = "";
@englishextra
englishextra / htmlentities.js
Last active May 12, 2016 11:21
A minimal html entities decoder/encoder using DOM
/*!
* A minimal html entities decoder/encoder using DOM.
* gist.github.com/englishextra/737e35d19bcb4ee62ab85c9f9b292842
* modified github.com/jussi-kalliokoski/htmlentities.js
* see issue github.com/jussi-kalliokoski/htmlentities.js/issues/1
* htmlentities.encode('<&>'); returns '&lt;&amp;&gt;';
* htmlentities.decode('&lt;&amp;&gt;'); returns '<&>';
* htmlentities is a shorthand for htmlentities.encode
*/
var htmlentities = (function (a) {
@englishextra
englishextra / appendAfter.js
Last active October 1, 2016 19:46
Adds Element AFTER NeighborElement
/*!
* Adds Element AFTER NeighborElement
* gist.github.com/englishextra/c19556b7a61865e3631cc879aaeb314e
* @param {String|object} e HTML Element to append after
* @param {Object} a target HTML Element
* appendAfter(e,a)
*/
var appendAfter=function(e,a){var p=a.parentNode||"",s=a.nextSibling||"";p&&s&&p.insertBefore(e,s);return!1;};