Skip to content

Instantly share code, notes, and snippets.

View SaneMethod's full-sized avatar

Christopher Keefer SaneMethod

View GitHub Profile
@SaneMethod
SaneMethod / jquery.transparentsubmit.js
Created March 1, 2013 19:20
jQuery transparent submission plugin - uses iFrames to allow for an 'ajax-like' submission of a form to some endpoint, and retrieve the json, html or text response offered by that server to said frame.
/**
* jQuery plugin for transparent submission of a form using an $.ajax-like interface.
* Usage Examples:
* $.transparentSubmit({dataType:'json', form:$('#myForm')})
* $('#myForm').transparentSubmit({dataType:'html'})
* Supports Deferred (.done, .fail, .when, etc.)
*/
(function($){
$.transparentSubmit = function(options){
var defer = $.Deferred(), // Deferred object whose promise we will hook into when adding .done, etc to calls
@SaneMethod
SaneMethod / minify.bat
Created May 28, 2013 19:51
CMD batch file for setting up basic minification for javascript and css using Closure Compiler and Closure Stylesheets.
@ECHO OFF
@setlocal enableextensions enabledelayedexpansion
IF "%1"=="--help" GOTO Usage
IF "%1"=="/?" GOTO Usage
REM set defaults
set ini=build.ini
set csspath=../static/css/
set jspath=../static/js/
set jsout=../static/js/compiled.js
@SaneMethod
SaneMethod / minify.sh
Created May 28, 2013 19:52
Minify javascript and css using Google closure compiler and closure stylesheets.
#!/bin/sh
#set defaults
ini=build.ini
csspath=../static/css/
jspath=../static/js/
jsout=../static/js/compiled.js
cssout=../static/css/compiled.css
js=
css=
@SaneMethod
SaneMethod / ajaxCacheTransport.js
Last active December 18, 2015 23:29
Ajax transport example for json, for ajax caching.
/**
* This function performs the fetch from cache portion of the functionality needed to cache ajax
* calls and still fulfill the jqXHR Deferred Promise interface.
* See also $.ajaxPrefilter
* @method $.ajaxTransport
* @params options {Object} Options for the ajax call, modified with ajax standard settings
*/
$.ajaxTransport("json", function(options){
if (options.localCache)
{
@SaneMethod
SaneMethod / ajaxCachePrefilter.js
Last active May 3, 2019 13:01
Ajax prefilter for caching, based on paul irish's work at https://github.com/paulirish/jquery-ajax-localstorage-cache, made to work with jqXHR Deferred Promises when paired with an appropriate ajaxTransport.
/**
* Prefilter for caching ajax calls - adapted from
* https://github.com/paulirish/jquery-ajax-localstorage-cache, made to work with jqXHR Deferred Promises.
* See also $.ajaxTransport.
* New parameters available on the ajax call:
* localCache : true, // required if we want to use the cache functionality
* cacheTTL : 1, // in hours. Optional
* cacheKey : 'post', // optional
* isCacheValid : function // optional - return true for valid, false for invalid
* @method $.ajaxPrefilter
@SaneMethod
SaneMethod / AccTimers.js
Last active December 23, 2015 18:39
(More) accurate timers for javascript.
(function(window){
window.performance = window.performance || {};
performance.now = performance.now || function(){
return +new Date();
};
function AccurateInterval(options){
this.startTime = 0;
this.elapsed = 0;
this.timeout = 0;
@SaneMethod
SaneMethod / jquery-ajax-blob-arraybuffer.js
Last active March 14, 2022 17:57
Ajax transports to allow the sending/receiving of blobs and array buffers via the familiar jquery ajax function.To send, set data to the blob or arraybuffer to be sent, and add 'processData:false' to the ajax options.To receive, specify the 'dataType' as blob or arraybuffer in the ajax options.
(function($){
/**
* Register ajax transports for blob send/recieve and array buffer send/receive via XMLHttpRequest Level 2
* within the comfortable framework of the jquery ajax request, with full support for promises.
*
* Notice the +* in the dataType string? The + indicates we want this transport to be prepended to the list
* of potential transports (so it gets first dibs if the request passes the conditions within to provide the
* ajax transport, preventing the standard transport from hogging the request), and the * indicates that
* potentially any request with any dataType might want to use the transports provided herein.
*
@SaneMethod
SaneMethod / customwindow.jquery.js
Created February 21, 2014 18:50
Google Maps custom info window overlay, using jQuery. See also http://www.artandlogic.com/blog/2014/02/custom-google-maps-info-windows for details.
/**
* Create a custom overlay for our window marker display, extending google.maps.OverlayView.
* This is somewhat complicated by needing to async load the google.maps api first - thus, we
* wrap CustomWindow into a closure, and when instantiating CustomWindow, we first execute the closure (to create
* our CustomWindow function, now properly extending the newly loaded google.maps.OverlayView), and then
* instantiate said function.
* Note that this version uses jQuery.
* @type {Function}
*/
(function(){
@SaneMethod
SaneMethod / customwindow.js
Created February 21, 2014 19:20
Custom google maps info window, no jquery. See also http://www.artandlogic.com/blog/2014/02/custom-google-maps-info-windows for details.
/**
* Create a custom overlay for our window marker display, extending google.maps.OverlayView.
* This is somewhat complicated by needing to async load the google.maps api first - thus, we
* wrap CustomWindow into a closure, and when instantiating CustomNativeWindow, we first execute the closure
* (to create our CustomNativeWindow function, now properly extending the newly loaded google.maps.OverlayView),
* and then instantiate said function.
* @type {Function}
* @see _mapView.onRender
*/
(function(){
@SaneMethod
SaneMethod / elideOptions.js
Last active August 29, 2015 14:00
jQuery plugin workaround for chrome bug which prevents display of visible options when some options are hidden. Also handles hiding/showing of options in apple webkit and internet explorer, which don't respect display:none for option elements (as of 06/2014).
(function($){
var userAgent = window.navigator.userAgent,
needsWrap = (userAgent.indexOf('Trident') !== -1 || userAgent.indexOf('AppleWebKit') !== -1);
/**
* Workaround for browsers that respect hidden options elements, but then fail to resize the select dropdown
* to display any visible elements beyond those that appear before any hidden elements - namely, Chrome.
* Based on the filter function, we either select all options that match (or, if invert is true, all that
* don't match), set them to disabled (with the expectation that there's a css rule hiding disabled options
* somewhere), and then pull the disabled options out of the DOM and insert them back in at the end of the
* select - this is tested as working in the most recent version of Chrome (as of this writing, v34).