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 / isValidId.js
Last active October 17, 2016 21:42
Check if string represents a valid HTML id
/*!
* Check if string represents a valid HTML id
* gist.github.com/englishextra/b5aaef8b555a3ba84c68a6e251db149d
* jsfiddle.net/englishextra/z19tznau/
* @param {String} a text string
* @param {Int} [full] if true, returns with leading hash/number sign
* isValidId(a,full)
*/
var isValidId = function(a, full) {
return full ? /^\#[A-Za-z][-A-Za-z0-9_:.]*$/.test(a) ? !0 : !1 : /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(a) ? !0 : !1;
@englishextra
englishextra / cito.fixed.js
Last active October 11, 2016 21:15
modified for babel citojs - v0.0.3
/*!
* modified for babel citojs - v0.0.3
* github.com/joelrich/citojs
* gist.github.com/englishextra/359e2fa19c14319a385cc4b47af0b597
* jsfiddle.net/englishextra/L9zrqd4L/
* closure-compiler.appspot.com/code/jscb32351779a4dd18f67fc6a53c7af5d44/default.js
* removed UMD wrapper
* Copyright (c) 2015, Joel Richard
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@englishextra
englishextra / earlyHasTouch.js
Last active October 9, 2016 19:32
add touch support class
/*!
* add touch support class
* gist.github.com/englishextra/3cb22aab31a52b6760b5921e4fe8db95
* jsfiddle.net/englishextra/z5xhjde8/
*/
var earlyHasTouch;
(function (d, s) {
if (d) {
var c = "ontouchstart" in d ? s : "no-" + s;
earlyHasTouch = c;
@englishextra
englishextra / Notifier42.js
Last active October 8, 2016 03:37
Toast messages with pure JS
/*!
* Notifier42
* Toast messages with pure JS
* gist.github.com/englishextra/5500a860c26d5e262ef3700d822ff698
* inspired by github.com/mlcheng/js-toast
* @param {String|Object} m text string or HTML ELement
* @param {Int} [n] any positive whole number, default: 0
* @param {String} t [additioal css class name]
* var nf=Notifier42("message",8000);setTimeout(function(){nf.destroy()},2000);
*/
@englishextra
englishextra / LoadingSpinner.js
Last active October 5, 2016 23:39
loading spinner
/*!
* loading spinner
* dependent on setAutoClearedTimeout
* gist.github.com/englishextra/24ef040fbda405f7468da70e4f3b69e7
* @param {Object} [cb] callback function
* @param {Int} [n] any positive whole number, default: 500
* LoadingSpinner.show();
* LoadingSpinner.hide(cb,n);
*/
var LoadingSpinner = function () {
@englishextra
englishextra / appendFragmentAfter.js
Created October 1, 2016 19:48
Adds Element as fragment AFTER NeighborElement
/*!
* Adds Element as fragment AFTER NeighborElement
* gist.github.com/englishextra/75020c8ba3b389b19d501d8ec88e3121
* @param {String|object} e HTML Element to append after
* @param {Object} a target HTML Element
* appendFragmentAfter(e,a)
*/
var appendFragmentAfter=function(e,a){"string"===typeof e&&(e=document.createTextNode(e));var p=a.parentNode||"",s=a.nextSibling||"",df=document.createDocumentFragment();p&&s&&df.appendChild(e)&&p.insertBefore(df,s);return!1;};
@englishextra
englishextra / prependBefore.js
Last active October 1, 2016 19:47
Adds Element BEFORE NeighborElement
/*!
* Adds Element BEFORE NeighborElement
* gist.github.com/englishextra/ad6b0ed6aa934434ddbb65d3a60ba28f
* @param {String|object} e HTML Element to prepend before
* @param {Object} a target HTML Element
* prependBefore(e,a)
*/
var prependBefore=function(e,a){var p=a.parentNode||"";p&&p.insertBefore(e,a);return!1;};
@englishextra
englishextra / styleIsLoaded.js
Created October 1, 2016 19:36
How can I check if a CSS file has been included already?
/*!
* How can I check if a CSS file has been included already?
* gist.github.com/englishextra/d00e7046c9957199ff3e87af693f38be
* stackoverflow.com/questions/18155347/how-can-i-check-if-a-js-file-has-been-included-already
* @param {String} h path string
* styleIsLoaded(h)
*/
var styleIsLoaded=function(h){var a=document.styleSheets||"";if(a)for(var b=0,d=a.length;b<d;b++)if(a[b].href==h)return!0;return!1};
@englishextra
englishextra / scriptIsLoaded.js
Last active October 1, 2016 19:34
How can I check if a JS file has been included already?
/*!
* How can I check if a JS file has been included already?
* gist.github.com/englishextra/403a0ca44fc5f495400ed0e20bc51d47
* stackoverflow.com/questions/18155347/how-can-i-check-if-a-js-file-has-been-included-already
* @param {String} s path string
* scriptIsLoaded(s)
*/
var scriptIsLoaded=function(s){for(var b=document.getElementsByTagName("script")||"",a=0;a<b.length;a++)if(b[a].getAttribute("src")==s)return!0;return!1};
@englishextra
englishextra / safelyParseJSON.js
Created October 1, 2016 19:30
parse JSON with no eval using JSON-js/json_parse.js
/*!
* parse JSON with no eval using JSON-js/json_parse.js
* with fallback to native JSON.parse
* gist.github.com/englishextra/4c0c2dec65953cae0d3b909ee64650f7
* @param {String} a JSON string
* safelyParseJSON(a)
*/
var safelyParseJSON=function(a){var w=window;try{return w.json_parse?json_parse(a):JSON.parse(a);}catch(e){console.log(e);}};