This file contains 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); |
This file contains 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 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 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
/** | |
* Grow (or shrink) an array - alters the array | |
* @param {number} length | |
* @param {?*...} add these entries and repeat | |
* @returns this | |
*/ | |
Array.prototype.grow = function(length, add) { | |
var i = 0, len = this.length, args = Array.prototype.slice.call(arguments, 1); | |
if (this.length < length) { | |
args = args.length ? args : [0]; |
This file contains 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
/** | |
* Perform a callback when an image has loaded, optionally on every load | |
* @param {function} callback | |
* @param {?boolean} repeat | |
* @returns {jQuerySelector} | |
*/ | |
$.fn.imageLoad = function(callback, repeat) { | |
return this.each(function() { | |
var $el = $(this), fn = function() { | |
callback.call(this, $el); |
This file contains 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
/** | |
* Draw a line between two elements | |
* @param {(jQuerySelector|string)} target | |
* @param {?Object} options | |
* @returns {jQuerySelector} | |
*/ | |
$fn.drawLine = function(target, options) { | |
var opts, | |
_uiLine = "ui-line", | |
get_relative = function(from_pos, from_size, to_pos, to_size, small, big, corners) { |
This file contains 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
/*Popover functionality*/ | |
$(window).on('resize', function(event) { | |
$('.show-text').not(this).popover('hide'); | |
}); | |
$(window).on('click', function(event) { | |
if (!$(event.target).hasClass("show-text")) { | |
$('.show-text').popover('hide'); | |
} | |
}); | |
$('.show-text').popover({ |
This file contains 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
/** | |
* Convert a css number type string into pixel units | |
* @param {jQuerySelector} $el | |
* @param {String} value | |
* @param {?Boolean} horiz | |
* @returns {Number} | |
*/ | |
function convertCSS($el, value, horiz) { | |
var val = parseFloat(value); | |
// console.log("convertCSS", value, value.replace(/[^a-z%]/g, ""), horiz) |
This file contains 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
/** | |
* Shortcut to getBoundingClientRect | |
* @param {Element} element | |
*/ | |
function getRect(element) { | |
if (element === window) { | |
return { | |
top: 0, | |
right: element.innerWidth, | |
bottom: element.innerHeight, |
This file contains 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
/** | |
* Levarage the wnidow.history object for AJAX website navigation | |
* @param {(Function|String|Number|null)} arg Use a function(url,isPop) to set the callback, a string for a url, and a number for a relative history url, finally "null" returns the current url | |
*/ | |
$.pushState = function(arg) { | |
var state = $.pushState; | |
if (state.index === undefined) { | |
var url = window.location.href; |
OlderNewer