Skip to content

Instantly share code, notes, and snippets.

View bgantick's full-sized avatar
👋

Brian Gantick bgantick

👋
View GitHub Profile
@bgantick
bgantick / targetBlank.js
Last active December 9, 2016 20:48
Open external links in a new tab/window
window.onload = function() {
var anchors = document.getElementsByTagName('a');
var a = new RegExp('/' + window.location.host + '/');
for (var i = 0; i < anchors.length; i++) {
if (!a.test(anchors[i])) {
anchors[i].setAttribute('target', '_blank');
}
}
};
@bgantick
bgantick / getCookie.js
Last active December 9, 2016 20:47
Function to get specific cookie value (returns str)
function getCookieVal(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
@bgantick
bgantick / paramify.js
Last active January 25, 2017 18:53
Get param from url
var qs = (function(a) {
if (a === '') return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' '));
}
return b;
})(window.location.search.substr(1).split('&'));
@bgantick
bgantick / emailvalidation.js
Last active December 9, 2016 20:44
js email validation
function validateEmail(uEmail) {
var filter = /^(([\w-\.]|([-]|[_]|[.]|[+]))+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(uEmail)) {
return true;
} else {
return false;
}
}

Keybase proof

I hereby claim:

  • I am bgantick on github.
  • I am bgantick (https://keybase.io/bgantick) on keybase.
  • I have a public key whose fingerprint is C15D 6266 A32C 8803 E8E2 5870 A7C6 7B89 C840 A62C

To claim this, I am signing this object:

@bgantick
bgantick / jquery-target-blank.js
Last active December 9, 2016 20:47
Open external links in a new tab
$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if (!a.test(this.href)) {
$(this).attr("target","_blank");
}
});