Skip to content

Instantly share code, notes, and snippets.

(function($){
$.widget("ui.mywidget", {
options: {
autoOpen: true
},
_create: function(){
// by default, consider this thing closed.
@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>
@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 / 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.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.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 / 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 / gist:1189524
Created September 2, 2011 19:02
FormField Mockup
<html>
<head>
<style type="text/css">
.readonlyField .label {
display: inline;
text-align: left;
font-size: 12pt;
font-weight: bold;
}
.readonlyField .label:after {
@donabrams
donabrams / RequireOnlyIfRequireExists.js
Created September 7, 2011 19:20
Optional use of require for jquery plugins (require not required)
requireOnlyIfRequireExists = function(deps, func) { if (require) {require(deps, func);} else { func(); }};
requireOnlyIfRequireExists(["jquery.min"], function () {
/*
Insert normal jquery plugin logic here
*/
});
@donabrams
donabrams / jquery.deferredPipeline.js
Created October 21, 2011 13:33
$.Deferred Pipeline
define(["jquery"], function($) {
//
// Given a list of functions that return a promise or an object,
// Set them up to execute them in order using those promises.
// and returns a promise that resolves after the last promises returned by the function pipeline resolves.
//
var deferredPipeline = $.deferredPipeline = function(/* [function, ]*/) {
//reversed pipeline
var toPipe = Array.prototype.slice.call(arguments).reverse();
if (toPipe.length == 0) {