Skip to content

Instantly share code, notes, and snippets.

View toddzebert's full-sized avatar
💭
coding, of course

Todd Zebert toddzebert

💭
coding, of course
View GitHub Profile
@toddzebert
toddzebert / asyncSim.js
Last active March 7, 2017 08:25
"simulates" an async function and passes either `res` directly or the result of `res()` to the callback function, see https://gist.github.com/toddzebert/cee6d8b0475275be0f48d7dfef142bd3
// requires https://gist.github.com/toddzebert/b4465de41b0f8d317d7a685604983c36
function asyncSim (res, data, onDone) {
var result = (typeof res === "function") ? res(data) : res;
setTimeout(function () { onDone(result); }
, randInt(400, 200));
};
@toddzebert
toddzebert / randInt.js
Last active March 7, 2017 08:25
a helper utility that returns a random integer; see https://gist.github.com/toddzebert/cee6d8b0475275be0f48d7dfef142bd3
function randInt (spread, base) {
return Math.floor(Math.random() * spread + (isNaN(base) ? 0: base));
}
@toddzebert
toddzebert / bpExport.demo.html
Created February 10, 2017 06:11
Sharing CSS breakpoints with JavaScript - Demo HTML
site breakpoint: <span class="my-site-breakpoint"></span>
<div class="my-div">
my div breakpoint: <span class="my-div-breakpoint"></span>
</div>
<div class="my-color-div"></div>
@toddzebert
toddzebert / bpExport.demo.js
Last active February 10, 2017 06:57
Sharing CSS breakpoints with JavaScript - Demo JavaScript
$(function() {
bodyBP = bpExport.breakpoint('body');
bodyBP.onChange(function(bp) {
$('.my-site-breakpoint').html(bp);
});
myDivBP = bpExport.breakpoint('.my-div');
myDivBP.onChange(function(bp) {
$('.my-div-breakpoint').html(bp);
@toddzebert
toddzebert / bpExport.js
Last active February 10, 2017 06:53
Sharing CSS breakpoints with JavaScript - JavaScript
// see https://www.lullabot.com/articles/importing-css-breakpoints-into-javascript
// module pattern
var bpExport = (function (bpExport) {
// this will create a closure
bpExport.breakpoint = function(sel) {
// define private state
var state = null;
@toddzebert
toddzebert / bpExport.demo.scss
Last active February 10, 2017 06:31
Sharing CSS breakpoints with JavaScript - Demo SCSS
// set our site's breakpoints
$site-breakpoints: (
"small": 320px,
"medium": 460px,
"large": 969px,
"x-large": 1061px,
"xx-large": 1284px
);
@include add-bp($site-breakpoints);
@toddzebert
toddzebert / bpExport.scss
Created February 10, 2017 06:02
Sharing CSS breakpoints with JavaScript - SCSS
@import "breakpoint";
// loop through the map and add the breakpoints
@mixin add-bp($bps) {
@each $bp-name, $bp in $bps {
@include add-breakpoint($bp-name, $bp);
}
}
// loop through the map and set `content`
@toddzebert
toddzebert / simpleMVC.Controller.js
Created January 23, 2017 08:59
The Controller module of a simple MVC implementation, in ES6 and module pattern
/**
* Controller module
*/
var simpleMVC = (function simpleMVC(simple) {
'use strict';
simple.Controller = function SimpleController(model, view) {
this._model = model;
this._view = view;
@toddzebert
toddzebert / simpleMVC.TwoWayView.js
Created January 23, 2017 08:51
The TwoWayView module of a simple MVC implementation, in ES6 and module pattern
/**
* A 2-way View Module
*/
var simpleMVC = (function simpleMVC(simple) {
'use strict';
// selector is a DOM element that supports .onChanged and .value
simple.TwoWayView = function simpleTwoWayView(model, selector) {
this._model = model;
@toddzebert
toddzebert / simpleMVC.OneWayView.js
Last active January 23, 2017 08:51
The OneWayView module of a simple MVC implementation, in ES6 and module pattern
/**
* A 1-way View Module
*/
var simpleMVC = (function simpleMVC(simple) {
'use strict';
simple.OneWayView = function simpleOneWayView(model, selector) {
this._model = model;
this._selector = selector;