Contrast and Brightness plugin for fabric.js

I’ve written a small plugin for the excellent fabric.js canvas library. Here’s the code you need, add it to your page after fabfic is loaded. fabric.Image.filters.BrightnessContrast = fabric.util.createClass(fabric.Image.filters.BaseFilter, { type: 'BrightnessContrast', initialize: function(options) { options || (options = { }); this.contrast = options.contrast || 0; this.brightness = options.brightness || 0; }, applyTo: function(canvasEl) { var […]

Javascript: Add URL parameter

Here’s a handy function for adding a new parameter to a URL: function addUrlParam(param, value) { var url = location.href; if (location.search.indexOf(param) != -1) return url; var hash = location.hash, sep = url.indexOf('?') == -1 ? '?' : '&'; return url.replace(hash,'') + sep + encodeURIComponent(param) + (value ? '=' + encodeURIComponent(value) : '') + hash; […]

Javascript addClass/removeClass functions

While looking for compact Javascript addClass and removeClass functions, I stumbled upon http://snipplr.com/view/3561/addclass-removeclass-hasclass/. This code allows for a few optimizations: The ‘match’ method is deprecated, ‘test’ should be used instead. The ‘addClass’ function references a non-existing ‘this’ object. The ‘removeClass’ function declares a new variable ‘reg’, which is unnecessary. The ‘removeClass’ function doesn’t handle multiple […]