This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Make sure a number is within a minimum and maximum | |
| * @param {number} min | |
| * @param {number} num | |
| * @param {number} max | |
| * @returns {number} | |
| */ | |
| Math.range = function(min, num, max) { | |
| return Math.max(min, Math.min(num, max)); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Split a string into an array of regex matches, or a single result if only a single match | |
| * @param {RegExp} r The pattern to check against | |
| * @return {Array|string|number} The matches | |
| */ | |
| String.prototype.regex = function(r) { | |
| var a = this.match(r), i, rx; | |
| if (a) { | |
| if (r.global) { | |
| if (/(^|[^\\]|[^\\](\\\\)*)\([^?]/.test(r.source)) { // Try to match "(blah" but not "\(blah" or "(?:blah" - ignore invalid regexp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Please note this uses my Math.range and String.regex methods | |
| /** | |
| * Convert a hex colour to a rgb/rgba value | |
| * @param {string} hex | |
| * @param {?number} opacity | |
| * @returns {string} | |
| */ | |
| function rgba(hex, opacity) { | |
| var colours = hex.regex(/#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})/i).map(function(val) { | |
| return Math.range(0, parseInt(val, 16), 255); |
NewerOlder