Skip to content

Instantly share code, notes, and snippets.

@ryanand26
ryanand26 / placeholder-shim.js
Created February 6, 2014 12:16
Shim for placeholder support (My version)
/*jslint bitwise: true, eqeqeq: true, passfail: false, nomen: false, plusplus: false, undef: true, evil: true */
/*global window, document, $, jQuery, LBI, self, Modernizr, setTimeout, define, require */
define("utils/placeholder-shim", function () {
var hasPlaceholder,
placeHolderClass = 'showing-placeholder';
function testForPlaceholder (){
var i = document.createElement('input');
return 'placeholder' in i;
}
@ryanand26
ryanand26 / jquery-validation-integrated.js
Created March 24, 2014 11:12
jQuery Validation integration
/*jslint bitwise: true, eqeqeq: true, passfail: false, nomen: false, plusplus: false, undef: true, evil: true */
/*global window, document, $, jQuery, LBI, self, Modernizr, setTimeout, define, require */
define(['validate', 'createFormError' ], function (validateInclude, createFormError) {
var validationInitialized = false,
isSelectValid = 'is-select-valid',
isSelectValidMobile = 'is-select-valid-mobile',
validationDefaults = {
errorClass: "has-error",
validClass: "is-valid-marker",
@ryanand26
ryanand26 / gist:9830443
Last active August 29, 2015 13:57
Basic Trident test
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trident Test</title>
@ryanand26
ryanand26 / centerOnLatLng
Last active August 29, 2015 14:05
Center google map whilst maintaining bounds
function centerOnLatLng(center) {
var map = this.map,
bounds = map.getBounds(),
ne = bounds.getNorthEast(),
sw = bounds.getSouthWest(),
neLatDif, swLatDif,
neLonDif, swLonDif,
newBoundary = new google.maps.LatLngBounds();
//Lat
@ryanand26
ryanand26 / gist:e03d6eacab6c474a34df
Last active August 29, 2015 14:13
Karma configuration
// given relative path test/fixtures/ to karma
// Important: These paths must be exposed in karma.conf.js
var path = '';
if (typeof window.__karma__ !== 'undefined') {
path += 'base/';
}
jasmine.getFixtures().fixturesPath = path + 'test/fixtures';
jasmine.getJSONFixtures().fixturesPath = path + 'test/fixtures';
/**
@ryanand26
ryanand26 / server.js
Last active August 29, 2015 14:18
Basic SSI Express server
var express = require("express"),
serveIndex = require('serve-index'),
connectSSI = require('connect-ssi'),
app = module.exports = express();
// serve directory listings
app.use(serveIndex(__dirname, {'icons': true}));
//catch shtml files and parse them
app.use(connectSSI({
@ryanand26
ryanand26 / looseLoremIpsum
Created April 8, 2015 14:37
Replace text with lorem ipsum
/*!
* Loose Lorem Ipsum replacer
*/
(function(window, document, $, undefined) {
'use strict';
var loremIpsum = ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua", "ut", "enim", "ad", "minim", "veniam", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "aliquip", "ex", "ea", "commodo", "consequat", "duis", "aute", "irure", "in", "reprehenderit", "voluptate", "velit", "esse", "cillum", "eu", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", "cupidatat", "non", "proident", "sunt", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum", "at", "vero", "eos", "et", "accusamus", "iusto", "odio", "dignissimos", "ducimus", "qui", "blanditiis", "praesentium", "voluptatum", "deleniti", "atque", "corrupti", "quos", "dolores", "quas", "molestias", "excepturi", "sint", "occaecati", "cupiditate", "non", "provident", "similique", "sunt", "in"
@ryanand26
ryanand26 / gist:a6306ae7327b9c926d6d
Last active August 29, 2015 14:19
Grunt - Express server definition
module.exports = function(grunt) {
var path = require('path');
grunt.initConfig({
//...
express : {
options : {
port : 80,
hostname : '*',
server : path.resolve(__dirname, 'server.js')
@ryanand26
ryanand26 / d3.axis.ticks.js
Created May 19, 2015 09:46
D3.js: Generate the ticks for an axis without having to render them to the svg. Allows us to adapt the tickSize and tickPadding to these values before drawing rather than afterwards.
/**
* Generate the tick values for a given axis
* Reference: https://github.com/mbostock/d3/blob/master/src/svg/axis.js
*/
function getAxisTicks(axis) {
var scale1 = axis.scale(),
tickArguments_ = axis.ticks(),
tickValues = axis.tickValues(),
ticks;
@ryanand26
ryanand26 / noTache.js
Created July 30, 2015 08:08
Very basic template renderer
/**
* Take a basic template and return a populated result
* Required until our use of mustache is greenlit
*/
var Renderer = function () {
var startPattern = '{{',
endPattern = '}}',
tagPattern = /\{\{([#,\/])([\w,.]*\}\})/, //matches all opening or closing list tags
instance = this;