Skip to content

Instantly share code, notes, and snippets.

@edeviant
edeviant / script.js
Created August 13, 2013 14:25
invocation to execute after document.write has been manipulated by third-party library.
$(document).ready(function() {
/** prime slots */
primeAllSlots(_slotSelector);
/** rock & roll */
var t = function(i,sw,f) {
i = i || 0; // count loops
sw = (!sw) ? false : (document.write.toString().indexOf('[native code]') > -1); // look for docwrite swap (brightTag)
f = f || 0; // flip count... render when it's back (2)
//console.log('called',i,sw,f);
CARS.pushDebug('[asyncAdRenderer]', 'Called ', i, sw, f);
@edeviant
edeviant / Gruntfile.js
Created July 30, 2013 21:56
minimal gruntfile with watch stylus as default task
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
stylus: {
buildall: {
files: [
{ expand: true, cwd: 'src/', src: ['**/*.styl'], dest: 'out', ext: '.css' }
],
options: {
@edeviant
edeviant / universalModel.js
Created July 25, 2013 00:39
Single universal model to avoid duplicate data source calls via Require or CanJS Model loads (this extends can.Model but there's really no reason at this point...). For cache-eligible data, presents an interface that can be configured to transparently cache or invalidate cache in local storage. Leverages Promises which return immediately to the …
/* ******************************* *
* Cars.com Universal Model
* Updated: APR 2013
* Version: AMD 1.0
* This file creates consistent
* model singleton for Cars.com
* @TODO incorporate stash for caching
* ******************************* */
define(['jquery', 'can', 'modules/common/stash'], function($, can, stash) {
@edeviant
edeviant / asyncAdRenderer.js
Last active December 20, 2015 05:09
Module for handling async ad rendering on Cars.com (given a document.write implementation for DFP or other ad serving platforms). Leverages modified Postscribe and htmlParser libraries (modified to work via AMD). Registers full event system for rending ads globally, specifically, or in new elements. Updates targeting each load via server for any…
/**
* Cars.com ad tag generator
* Updated: JUN 2013
* Version: AMD 1.5
* This file creates consistent ad logic for generated DFP tags for Cars.com ad serving
* @todo rules to ensure targeting data prioritization
* @todo document nomenclature/terminology
* @todo move to preferences.js
* @todo cache/clear targeting data where possible (gms/mvis)
* @doc http://proddev.cars.com/wiki/technical/core/advertising/async-ad-renderer
@edeviant
edeviant / stash.js
Created July 24, 2013 23:51
Module for custom interface around local storage options. Handles failover to cookie (via modified shim). Exposes generic handlers for storing, retrieving, and removing by data type or by straight key/value. Maintains reference data as saved/retrieved.
/**
* Cars.com Stash Module
* @version AMD 1.0
* @module modules/common/stash
* Provides a facade around local storage functionality
* - ensures a technology agnostic approach
* - ensure standard interface for storage crud
*/
define([], function() {
@edeviant
edeviant / zipCaptureForm.js
Created July 24, 2013 23:45
Base class for forms on Cars.com. Centralizes zip code validation and zip capture. Provides common functionality for form events and hooks for future validation rules. Leverage CanJS Control structure, sets defaults for all forms, and allows for overriding all options, including submit handler method after validation passes. Leverages Promises t…
/**
* zipCaptureForm.js
* Base class for creating a form with FE zip validation
* - handles form submit
* - handles server-side zip validation
* - handles presenting zip capture modal
*/
define(['jquery', 'can', 'jquerytools', 'canSuper'], function($, can) {
@edeviant
edeviant / deferredLoading.js
Created July 24, 2013 23:32
Module to defer loading of HTML elements until with viewport. Currently only watches images. Runs on every page of Cars.com. Uses jQuery, and leverages setTimeout loop instead of setInterval or window events to avoid memory leaks and minimize maintenance on-page.
/**
* A module to defer loading of assets (images-only at current) until viewed by user.
* Each image will handle it's own logic of whether to load or not via custom event.
* To use, load module and call init();
* This does have an SEO impact for images; ensure that implementing is desired.
* The element selector is assumed to be an img resource with a data- attribute.
* @author Clay Johnson
* @version 20130124
* @example
* To defer an image load, insert:
@edeviant
edeviant / functionAfterJQ.js
Created March 25, 2013 14:58
Method for loading a function after jQuery is available.
var loadAfterJQ = function(fn) {
if (!!window.jQuery) {
fn();
console.log('jQuery is loaded');
} else {
console.log('jQuery is not loaded');
setTimeout(function() { loadAfterJQ(fn) }, 250);
}
}
@edeviant
edeviant / persistentModuleTemplate.js
Last active December 15, 2015 06:19
Template for 'persistent' AMD module with jQuery, defaults, and debug support
/**
* Template for 'persistent' AMD module
* - with jQuery and default attributes support
* - setDefaults is only public method for module
* @example
* after module is loaded, fire with:
* $(window).trigger("EVENTNAME",[{ "foo": "bar" }]);
*/
define(['jquery'], function($) {