2011-07-22 23:26:16 +00:00
|
|
|
if (typeof window.console === 'undefined') {
|
|
|
|
window.console = { log: function() { return false; } };
|
|
|
|
}
|
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
function makeSlug(val, sep) { // code largely inspired by http://www.thewebsitetailor.com/jquery-slug-plugin/
|
2010-07-23 20:20:09 +00:00
|
|
|
if (typeof val == 'undefined') return('');
|
|
|
|
if (typeof sep == 'undefined') sep = '_';
|
|
|
|
var alphaNumRegexp = new RegExp('[^a-zA-Z0-9\\' + sep + ']', 'g');
|
|
|
|
var avoidDuplicateRegexp = new RegExp('[\\' + sep + ']{2,}', 'g');
|
|
|
|
val = val.replace(/\s/g, sep);
|
|
|
|
val = val.replace(alphaNumRegexp, '');
|
|
|
|
val = val.replace(avoidDuplicateRegexp, sep);
|
|
|
|
return val.toLowerCase();
|
2010-06-10 13:30:32 +00:00
|
|
|
}
|
2010-06-14 13:04:01 +00:00
|
|
|
|
2011-08-17 02:23:14 +00:00
|
|
|
function addParameterToURL(key, value) { // code from http://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript
|
|
|
|
key = encodeURIComponent(key); value = encodeURIComponent(value);
|
|
|
|
|
|
|
|
var kvp = document.location.search.substr(1).split('&');
|
|
|
|
|
|
|
|
var i = kvp.length; var x; while(i--) {
|
|
|
|
x = kvp[i].split('=');
|
|
|
|
|
|
|
|
if (x[0] == key) {
|
|
|
|
x[1] = value;
|
|
|
|
kvp[i] = x.join('=');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < 0) { kvp[kvp.length] = [key,value].join('='); }
|
|
|
|
|
|
|
|
//this will reload the page, it's likely better to store this until finished
|
|
|
|
document.location.search = kvp.join('&');
|
|
|
|
}
|
|
|
|
|
2010-12-30 14:24:47 +00:00
|
|
|
(function() {
|
|
|
|
String.prototype.trim = function() {
|
|
|
|
return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
|
|
|
|
}
|
2011-08-11 20:45:46 +00:00
|
|
|
|
|
|
|
String.prototype.repeat = function(num) {
|
|
|
|
for (var i = 0, buf = ""; i < num; i++) buf += this;
|
|
|
|
return buf;
|
|
|
|
}
|
2011-03-20 10:21:07 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
Object.size = function(obj) {
|
|
|
|
var size = 0, key;
|
|
|
|
for (key in obj) {
|
|
|
|
if (obj.hasOwnProperty(key)) size++;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
};
|