Skip to content

Instantly share code, notes, and snippets.

<form>
<input type="text" class="form-control" id="name-input" placeholder="Your name">
<input type="email" class="form-control" id="email-input" placeholder="Your email">
<textarea id="message-input" class="form-control" placeholder="What did you want to tell us?"></textarea>
<button type="submit" class="btn btn-default" id="submit-button">Send Message</button>
</form>
<script>
jQuery(document).ready(function($) {
if (typeof console === 'undefined') {
console = {};
console.log = function() {
return;
}
}
@jtribble
jtribble / external-links.js
Created April 23, 2015 20:46
Open external links in a new tab
@jtribble
jtribble / override-onclick.js
Last active August 29, 2015 14:21
For those frustrating times when you need to override an onclick event.
jQuery(document).ready(function($) {
var offendingElement = $('.dumb-thing');
offendingElement.each(function() {
$(this).data('onclick', this.onclick);
this.onclick = function(event) {
if (somethingIsWrong()) {
return false; // don't call the onclick
@jtribble
jtribble / cookies.js
Created May 22, 2015 17:42
Library for managing document cookies
/*\
|*|
|*| :: cookies.js ::
|*|
|*| A complete cookies reader/writer framework with full unicode support.
|*|
|*| Revision #1 - September 4, 2014
|*|
|*| https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
|*| https://developer.mozilla.org/User:fusionchess
/**
* Is string a valid email address?
*
* @param {string} str
* @return {boolean}
*/
var validEmail = function (str) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(str);
};
@jtribble
jtribble / valid-phone.js
Last active July 25, 2016 04:55
Is string a valid us phone number
/**
* Is string a valid phone number?
*
* @param {string} str
* @return {boolean}
*/
var isValidPhone = function (str) {
if (!str) return false;
var count = str.replace(/[^0-9]/g, '').length;
return count == 10 || count == 11;
@jtribble
jtribble / valid-zip.js
Last active September 23, 2015 02:21
Is string a valid zip code
/**
* Is string a valid zip code?
*
* @param {string} str
* @return {boolean}
*/
var isValidZip = function (str) {
return /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(str);
};
@jtribble
jtribble / get-url-param.js
Last active November 11, 2015 17:25
Get URL Parameter
/**
* Get URL param
*
* @param {string} param
* @return {string|null}
*/
var getUrlParam = function (param) {
// if input is invalid or there are no query params, return null
if (typeof param !== 'string' || location.search === '') return null;