Skip to content

Instantly share code, notes, and snippets.

View onestepcreative's full-sized avatar

Josh McDonald onestepcreative

View GitHub Profile
@onestepcreative
onestepcreative / isjquery.js
Created April 2, 2014 03:11
check if variable is jQuery object
var isjquery = function(data) {
// If data is already a jQuery object
if(data instanceof jQuery) {
// Do nothing different
data = data;
// Otherwise
} else {
@onestepcreative
onestepcreative / vanilla-selector.js
Created March 20, 2014 19:05
javascript selector not requiring jQuery
var S = function (selector, context) {
if (typeof selector === 'string') {
if (context) {
var cont;
if (context.jquery) {
cont = context[0];
if (!cont) return context;
} else {
cont = context;
}
@onestepcreative
onestepcreative / foreach.js
Created March 17, 2014 22:24
for each loop helper from hammer.js
var Obj = {
each: function(obj, iterator, context) {
var i, o;
// native forEach on arrays
if ('forEach' in obj) {
obj.forEach(iterator, context);
}
// arrays
else if(obj.length !== undefined) {
function scopeJacker(name) {
var mapper = function() {
dev.log('mapper called');
var childmapper = function() {
dev.log('child mapper with param: ' + name);
@onestepcreative
onestepcreative / chunk-it-up.js
Created March 9, 2014 00:46
helper function to quickly break up array into smaller equal size arrays
function chunkitup(arr, chunks) {
var len = arr.length;
var out = [];
var i = 0;
while (i < len) {
var chunkSize = Math.ceil((len - i) / chunks--);
.step {
transition: opacity 200ms ease-in-out;
opacity: 0;
visibility: hidden;
z-index: 4;
}
.step.active { visibility: visible; opacity: 1 }
@onestepcreative
onestepcreative / devmode-console-helper.js
Last active October 27, 2020 19:55
Color code your console log messages with a shorter syntax to console.log and easily turn off console logging by setting a DEV_MODE variable to false.
/*
Author: Josh McDonald
Twitter: @onestepcreative
Website: joshmcdonald.net
A simple helper to log color coded messages to the
javascript console, using a shorter syntax to console.log
You can leave your dev.log() statements scattered throughout
// Define class to hold all cart drop related items
cartDrop: {
// Initialize the cart bindings, or whatever
init: function() { ... },
events: {
bind: function() {
// sample: $(cart-trigger).on(click, BERG.cartDrop.events.open);
@onestepcreative
onestepcreative / check_media_query.js
Last active March 27, 2020 07:41
Fast way to check media queries in javascript (based on Foundation 5 sizing)
// Each statement returns true or false based on current viewport
// The EM units are based on html, body { font-size: 100%; } CSS
window.MQ = {
// max-width 640px mobile-only styles
small : (matchMedia('only screen and (max-width: 40em)').matches),
// min-width 641px and max-width 1024px screen only
medium : (matchMedia('only screen and (min-width:40.063em) and (max-width:64em)').matches),
@onestepcreative
onestepcreative / sample_css_file.css
Created December 10, 2013 19:03
A sample stylesheet to illustrate coding standards.
/* =============================================
Name: Josh McDonald
Company: CrystalCommerce
Copyright: 2013, All Rights Reserved
Table of Contents:
_General Site Globals