Skip to content

Instantly share code, notes, and snippets.

@donabrams
donabrams / ie-add-class.js
Created July 5, 2011 13:32
Add class ieX where X is version to enclosing html tag
(function () {
"use strict";
var browserClass = null;
if (navigator.appName === 'Microsoft Internet Explorer') {
if (navigator.appVersion.indexOf('MSIE 6', 0) !== -1) {
browserClass = "ie6";
} else if (navigator.appVersion.indexOf('MSIE 7', 0) !== -1) {
browserClass = "ie7";
} else if (navigator.appVersion.indexOf('MSIE 8', 0) !== -1) {
browserClass = "ie8";
@donabrams
donabrams / jquery.sureSubmit.js
Created February 11, 2011 21:50
if submitting via javascript, the submit event is not triggered. This makes sure it works! jquery function FTW
$.fn.sureSubmit = function(func) {
this.bind("submit", func).each(function(i, d) {
if (!d._origSubmit) {
d._origSubmit = d.submit;
d.submit = function() {
func();
this._origSubmit();
};
} else {
var f2 = d.submit;
@donabrams
donabrams / jquery.templatewrapper.js
Created February 1, 2011 19:46
Wrapper around jquery template that allows
//
// This is a wrapper around the jquery template library.
//
// The function to notice is:
// applyTemplate(data/{}, target/DOMNode,
// callback/function, keepPreviousTemplate/boolean)
// Once a template is instanced, calling this function will apply
// the template with the given data, then call the callback with
// no arguments.
//
@donabrams
donabrams / jquery.cache.js
Created February 1, 2011 19:28
Simple js caching with queuing
//
// This is a cache implemenation
// You can synchronously put(), contains() and markAsLoading().
// You can asynchronously get() and getput() and putget().
//
// get() is asynchronous because it might wait until a put() is called if
// the key is marked as loading.
// key is whatever you want it to be, required.
// callback is an optional function that takes 2 arguments:
// success/boolean and the value/?
@donabrams
donabrams / jquery.pollingwait.js
Created February 1, 2011 19:26
Polling wait for jquery
//
// This polls a function at max $max_attempts until true,
// then executes a function.
// The scope is likely this, but ya never know.
//
// TODO: add failure mechanism
$.pollingWait = function(max_attempts, delay, condFunc, condScope, func, scope /*, arguments */ ) {
var worker = function(attempts, max_attempts, delay, flagFunc, flagScope, func, scope, args) {
if (attempts >= max_attempts) {
return false;
@donabrams
donabrams / edit.html
Created February 1, 2011 15:00
coa templates
<div class="coa">
<form name="${formName}">
<div class="chartFields">
<div id="messages">
{{if messages && messages.length > 0}}
<ul class="messages">
{{each messages}}
<li>${$value}</li>
{{/each}}
</ul>
(function($){
$.widget("ui.mywidget", {
options: {
autoOpen: true
},
_create: function(){
// by default, consider this thing closed.