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
(function addUtmParams(source, medium, campaign) { | |
$("a").each(function () { | |
var $this = $(this); | |
var linkHref = $this.attr("href"); | |
if (linkHref.indexOf(window.location.hostname) < 0) { | |
var updateLink = updateQueryString({ | |
utm_source: source, | |
utm_medium: medium, | |
utm_campaign: campaign | |
}, linkHref); |
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
function UpdateQueryString(key, value, url) { | |
if (!url) url = window.location.href; | |
var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"); | |
if (re.test(url)) { | |
if (typeof value !== 'undefined' && value !== null) | |
return url.replace(re, '$1' + key + "=" + value + '$2$3'); | |
else { | |
var hash = url.split('#'); | |
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, ''); |
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
function parseURL(url) { | |
var a = document.createElement('a'); | |
a.href = url; | |
return { | |
source: url, | |
protocol: a.protocol.replace(':',''), | |
host: a.hostname, | |
port: a.port, | |
query: a.search, | |
params: (function(){ |
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
function throttle(delay, callback) { | |
var previousTime = new Date().getTime(); | |
return function() { | |
var newTime = new Date().getTime(); | |
if ((newTime - previousTime) > delay) { | |
previousTime = newTime; | |
callback.apply(null, arguments); | |
} | |
}; | |
} |
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
function debounce (delay, callback) { | |
var timeout = null; | |
return function (){ | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
var context = this; | |
var args = arguments; | |
timeout = setTimeout(function(){ | |
callback.apply(context, args); |
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
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; | |
var FN_ARG_SPLIT = /,/; | |
var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/; | |
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; | |
var $injectorMinErr = minErr('$injector'); | |
function annotate(fn) { | |
var $inject, | |
fnText, | |
argDecl, | |
last; |
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
function toJson(obj) { | |
return JSON.stringify(obj, function(k,v) { return v; }, ' ') | |
} |
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
function getTimeStamp() { | |
var now = new Date(); | |
return ((now.getMonth() + 1) + '/' + | |
(now.getDate()) + '/' + | |
now.getFullYear() + " " + | |
now.getHours() + ':' + | |
((now.getMinutes() < 10) | |
? ("0" + now.getMinutes()) | |
: (now.getMinutes())) + ':' + | |
((now.getSeconds() < 10) |
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
/* | |
* @param {Object|Array|Date|string|number} obj Input to be serialized into JSON. | |
* @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace. | |
* @returns {string|undefined} JSON-ified string representing `obj`. | |
*/ | |
function toJson(obj, pretty) { | |
if (typeof obj === 'undefined') return undefined; | |
return JSON.stringify(obj, toJsonReplacer, pretty ? ' ' : null); | |
} |