Skip to content

Instantly share code, notes, and snippets.

@chicagoworks
chicagoworks / $.fn.delegate.js
Created December 24, 2010 18:48
Override jquery.delegate() to accept an object
/**
* Override .delegate()
* if 'selector' is an object loop over the object and call .live() for each item
* otherwise it call .live() just like the original .delegate().
* Roughly similar to the way the map is implemented in .bind().
*/
$.fn.delegate = function(selector, types, data, fn) {
if (typeof selector === "object") {
for (var sel in selector) {
for (var type in selector[sel]) {
@chicagoworks
chicagoworks / jQuery.stringify.js
Created December 24, 2010 19:05
jQuery.stringify() utility
/**
* converted stringify() to jQuery plugin.
* serializes a simple object to a JSON formatted string.
* Note: stringify() is different from jQuery.serialize() which URLEncodes form elements
* UPDATES:
* Added a fix to skip over Object.prototype members added by the prototype.js library
* USAGE:
* jQuery.ajax({
@chicagoworks
chicagoworks / window.location.query
Created December 25, 2010 16:00
load and parse querystring, then append to name/values to window.location.query
(function() {
var arr = decodeURIComponent(window.location.search.substr(1)).replace(/\+/g," ").split('&'), p;
window.location.query = {};
for (var i = 0; i < arr.length; i++) {
p = arr[i].split('=');
window.location.query[p[0]] = p[1];
}
})();
@chicagoworks
chicagoworks / string-prototype.js
Created December 26, 2010 17:08
String object additions
//==== General Enhancements to Javascript ===========================================================
// Replace repeated spaces, newlines and tabs with a single space
String.prototype.normalize = function() {return this.replace(/^\s*|\s(?=\s)|\s*$/g, "");}
//http://www.somacon.com/p355.php
//Trim: Strip leading and trailing white-space
//NOTE: can also use jQuery.trim
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
@chicagoworks
chicagoworks / array-prototype.js
Created December 26, 2010 17:09
Array object additions
//implement shift and unshift on Array prototype
//http://www.javascriptkit.com/javatutors/oopjs2.shtml
if(!Array.prototype.shift) { // if this method does not exist..
Array.prototype.shift = function(){
firstElement = this[0];
this.reverse();
this.length = Math.max(this.length-1,0);
this.reverse();
@chicagoworks
chicagoworks / ie-fix-flicker.js
Created December 26, 2010 17:22
Fix flicker of background images in IE
//==== Fix flicker of background images in IE
//http://ajaxian.com/archives/no-more-ie6-background-flicker
//http://support.microsoft.com/?scid=kb;en-us;823727&spid=2073&sid=global
//http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=1&postId=1104
//Executes proprietary command to force IE to cache all background images which prevents the browser from fetching the same image repeatedly when using CSS hover background repositioning
if($.browser.msie && parseInt($.browser.version) === 6) {
try {
document.execCommand("BackgroundImageCache",false,true);
} catch(e) {
@chicagoworks
chicagoworks / jQuery-hasEvent-test.html
Created December 28, 2010 13:31
jQuery plugin to check if elements have a given event. Updated to work with .live() and .delegate() events.
<body>
<div id="wrapper" class="great-grand-parent">
<div class="grand-parent">
<div class="parent">
<button id="foo" class="button">foo (click)</button>
<button id="bar" class="button">bar (live click)</button>
<button id="baz" class="button">baz (#wrapper delegate)</button>
</div>
@chicagoworks
chicagoworks / rsa-encrypt-decrypt-roundtrip-test.asp
Created December 28, 2010 13:42
Port of the RSA algo to javascript and vb-script. Used to for low-level encryption on non-https site.
<%
REM: An excerpt from RSA Security site FAW "Is RSA patented?"
REM: http://www.rsasecurity.com/rsalabs/faq/6-3-1.html
REM: The patent for the RSA algorithm (U.S. Patent 4,405,829) was issued on September 20, 1983,
REM: exclusively licensed to RSA Security Inc. by the Massachusetts Institute of Technology,
REM: with an expiration date of September 20, 2000. RSA Security maintained a standard,
REM: royalty-based licensing policy that could be modified for special circumstances.
REM: In the U.S., a license has been needed to ëëmake, use or sellíí products that included
REM: the RSA algorithm. However, RSA Security has long allowed free non-commercial use of
REM: the RSA algorithm, with written permission, for academic or university research purposes.
@chicagoworks
chicagoworks / development-sidebar.html
Created December 28, 2010 13:49
Sidebar for firefox to help when developing sites, debugging code etc.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta http-equiv="expires" content="-1"/>
<meta http-equiv="pragma" content="no-cache"/>
<title>Scenario Runner</title>
<link href="/public/stylesheets/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
@chicagoworks
chicagoworks / jqueryui-tabs-activate.js
Created December 28, 2010 21:54
jQueryui tabs extension. $(el).tabs('activate', tab) is a mix of tabs('add') and tabs('select'). If the tab exists it is selected, if not it iis created. $(el).tabs(close) removes the tab but selects the tab to the left instead of the tab to the r
(function($) {
$.fn.extend($.ui.tabs.prototype, {
//use the same signature as add
activate : function(url, label, index) {
console.log(index)
var self = this,
index = index || self.anchors.length - 1;
//loop thru the tab.anchors collection and look for tab with a matching href
//If tab is local then compare the URL with the anchor or hash (eg #anchor5)
//If the tab is remote then compare the URL with .data('href.tabs')