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; |
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 that we can't accidentally iterate over custom methods | |
* @param {Object} proto | |
* @param {string} fName | |
* @param {function(?)} fn | |
*/ | |
function defineProperty(proto, fName, fn) { | |
if (!proto[fName]) { | |
proto[fName] = fn; | |
(Object.defineProperty || $.noop)(proto, fName, {"enumerable": false}); |
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
/** | |
* Compare two strings accounting for multi-digit numbers | |
* @param {(string|number)} a First string to compare | |
* @param {(string|number)} b Second string to compare | |
* @return {number} 0 if they match, -1 if a comes before b, +1 if b comes before a | |
*/ | |
function strnatcasecmp(a, b) { | |
a = ("" + a).toLowerCase(); | |
b = ("" + b).toLowerCase(); |
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 |
OlderNewer