Skip to content

Instantly share code, notes, and snippets.

View furf's full-sized avatar
🎯
Focusing

Dave Furfero furf

🎯
Focusing
View GitHub Profile
/**
* jQuery hoverClass plugin
*/
$.fn.hoverClass = function(className) {
return this.each(function() {
var $this = $(this);
$this.hover(function() {
$this.addClass(className);
}, function() {
$this.removeClass(className);
@furf
furf / dateBoundaries.js
Created April 7, 2009 12:34
Date boundary functions
/* Useful date functions if you're building a calendar */
var getStartOfCurrentDay = function(date) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
};
var getStartOfNextDay = function(date) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
};
/* parseQueryParameters & parseFragmentIdentifiers */
var setValue = function(obj, prop, val) {
if (!(prop in obj)) {
obj[prop] = val;
} else {
if (!(obj[prop] instanceof Array)) {
obj[prop] = [obj[prop]];
}
obj[prop].push(val);
var stress = function(fn, iterations) {
iterations = iterations || 1;
var result;
var start = new Date();
for (var i = 0; i < iterations; ++i) {
result = fn();
};
var _parseHTMLFromDOMElement = function(el) {
if (el.outerHTML) {
return el.outerHTML;
} else {
var sandbox = document.createElement('DIV');
sandbox.appendChild(el.cloneNode(true));
return sandbox.innerHTML;
}
};
/**
* $.fn.unwrap
* Unwraps an element (replaces an elements parent with the element)
*
* NO LONGER NECESSARY AS OF jQuery 1.4
*
* Example:
* $('#foo').unwrap();
* Will replace:
* <div><span id="foo">bar</span></div>
/**
* @class PeriodicalExecuter
* @param {Function} callback
* @param {Number} interval
* @param {Boolean} defer
* @constructs
*/
var PeriodicalExecuter = function(callback, interval, defer) {
this.callback = callback;
var bind = function(fn, obj /*, defaults */) {
var scope = obj || window, defaults;
fn = (typeof fn === 'string') ? scope[fn] : fn;
// If no defaults are supplied, return the lightweight callback
if (arguments.length < 3) {
return function() {
fn.apply(scope, arguments);
/**
* isDST
* Returns true if the supplied date (default Today) is DST
*/
var isDST = function(date) {
date = date ? new Date(date) : new Date();
var winter = new Date(date.getFullYear(), 0, 1);
return (date.getTimezoneOffset() !== winter.getTimezoneOffset());
};
// Abstract methods and interfaces
/**
* AbstractMethod factory class
*
* @method AbstractMethod
* @param {string} methodName Name of the method
* @return {type} Return value description
*/
var AbstractMethod = function(methodName) {