Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Pjura mpjura

  • Hearst Digital Media
  • NY
View GitHub Profile
@mpjura
mpjura / override-document-write.js
Last active Aug 29, 2020
Override document.write
View override-document-write.js
(function() {
var old = document.write;
document.write = function( content ) {
if ( "interactive" === document.readyState ) {
console.log("document.write called after page load: ", content );
// optional.. safely append the content
// document.body.appendChild( content );
return;
}
@mpjura
mpjura / constant.js
Last active May 3, 2016
Constants Implementation
View constant.js
define( "constants", [ "utils" ], function( Utils ) {
/**
* _constants is a private object that will hold the
* constant values. Hidden behind a closure to prevent
* modules from changing "constant" values once set.
* @type {Object}
*/
var _constants = {},
/**
@mpjura
mpjura / SassMeister-input.scss
Created Jan 18, 2016
Generated by SassMeister.com.
View SassMeister-input.scss
// ----
// libsass (v3.3.2)
// ----
%placeholder {
width: 100px;
height: 100px;
}
%placeholder {
@mpjura
mpjura / mediator.js
Last active Dec 14, 2015
Mediator Mixin
View mediator.js
var Mediator = {
channels: {},
subscribe: function( channel, fn, ctx ){
var channels = this.channels;
if ( !channels[ channel ] ){ channels[ channel ] = []; }
channels[ channel ].push({ context: ctx || this, callback: fn });
@mpjura
mpjura / transitionend-event-map.js
Created Feb 8, 2013
Transition End Event Name Map. Uses Modernizr.
View transitionend-event-map.js
var transEndEvent = {
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd otransitionend',
'msTransition' : 'MSTransitionEnd',
'transition' : 'transitionend'
}[ Modernizr.prefixed('transition') ];
@mpjura
mpjura / _article.scss
Last active Dec 11, 2015
Typography/Layout Placeholders
View _article.scss
// base _article.scss
// ------------------
.article-hed {
@extend %layout-article-hed;
@extend %type-article-hed;
}
.article-dek {
@extend %layout-article-dek;
@extend %type-article-dek;
@mpjura
mpjura / pixel-percent.js
Created Oct 24, 2012
PixelToPercent / PercentToPixel
View pixel-percent.js
/*jshint browser:true */
/*global _ */
//requires underscore.js for debounced function
(function(win, _){
"use strict";
var width = win.innerWidth,
handleResize;
win.pixelToPercent = function pixelToPercent(pixel){
View get-params.js
function getParams(key){
var url = window.location.href,
params = {}, i;
url = url.split('#')[0].split('?')[1];
if ( !url ) return undefined;
url = url && url.split('&');
while ( i = url.shift() ){
i = i.split('=');
params[ i[0] ] = i[1] || true;
}
@mpjura
mpjura / gist:3782195
Created Sep 25, 2012 — forked from remy/gist:350433
Storage polyfill
View gist:3782195
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@mpjura
mpjura / to-dollars
Created Aug 26, 2012
Function that converts numbers to dollar amounts
View to-dollars
/*jshint devel:true */
(function(){
"use strict";
var toDollarAmount = function toDollarAmout(amount, returnAsString){
var ret;
if ( 'number' !== typeof amount ){
return false;
}
ret = amount.toFixed(2);
return ( returnAsString ) ? '$' + ret : +ret;