Overriding setInterval with a better implementation

JavaScript includes two built-in options for timing and delaying actions, setInterval() and setTimeout(). These functions have been around since before the first ECMA specifications, so their implementations across browsers are largely non-standardized and inconsistent. I’ve noticed some problems with setInterval(), particularly when it’s left in a background tab. See the issues and how to solve them

Tagged with: ,
Posted in Custom Library Functions, GitHub, JavaScript

Graceful degradation of jQuery event handlers

If you saw my post on SharePoint custom ribbon actions, you may have noticed the section where I had to lay out several options for jQuery’s persistent event handlers because I couldn’t know which version of jQuery the solution would be used with. Since I’ve written a few projects that are designed to be inserted into existing sites, I thought it would be a good idea to build a system to easily manage the graceful degradation of these handlers. How I did it

Tagged with:
Posted in Custom Library Functions, GitHub, JavaScript, jQuery

Get query string values from JavaScript

I found this code a while ago, probably somewhere on Stack Overflow, and it’s served me well ever since. It returns a data object filled with the key-value pairs of the query string. Try it!

Tagged with:
Posted in Custom Library Functions, JavaScript, Try It

Rounding prototypes for JavaScript

JavaScript does include some standard methods for rounding numbers, but if you’re working on a project that involves calling them frequently, it can get a little tiring. Especially if you need to round to a certain number of decimal places as opposed to an integer. I haven’t encountered this situation much, but I though it would be a neat exercise for some new Number.prototype methods. Try it!

Tagged with:
Posted in Custom Library Functions, JavaScript, Try It

A better JavaScript random number generator

Every time I needed a random number in JavaScript, I always ended up building some weird, difficult to read manipulation of the Math.random() method to get a value in the range I needed. After doing this a few times on a few different projects, I decided it would be a worthwhile effort to concoct an all-in-one JavaScript random number generator. Try it!

Tagged with:
Posted in Custom Library Functions, JavaScript, Try It