Files
CHOMPStation2/nano/js/nano_config.js
Mark Aherne (Faerdan) eef5013d79 NanoUI Updates.
* Restructured HTML in an attempt to fix the "blank UI" issue.
* Added a crap ton of debugging messages.
* Added a loading message to the UI.
2014-01-08 02:30:33 +00:00

100 lines
2.4 KiB
JavaScript

// NanoConfig is the place to store utility functions
var NanoConfig = function ()
{
return {
init: function ()
{
if (typeof jQuery == 'undefined') {
alert('ERROR: jQuery failed to load!');
}
if (typeof $.views == 'undefined') {
alert('ERROR: JSRender failed to load!');
}
}
}
} ();
NanoConfig.init();
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
};
if (!String.prototype.format)
{
String.prototype.format = function (args) {
var str = this;
return str.replace(String.prototype.format.regex, function(item) {
var intVal = parseInt(item.substring(1, item.length - 1));
var replace;
if (intVal >= 0) {
replace = args[intVal];
} else if (intVal === -1) {
replace = "{";
} else if (intVal === -2) {
replace = "}";
} else {
replace = "";
}
return replace;
});
};
String.prototype.format.regex = new RegExp("{-?[0-9]+}", "g");
};
Object.size = function(obj) {
var size = 0, key;
for (var key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
if(!window.console) {
window.console = {
log : function(str) {
return false;
}
};
};
String.prototype.toTitleCase = function () {
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|vs?\.?|via)$/i;
return this.replace(/([^\W_]+[^\s-]*) */g, function (match, p1, index, title) {
if (index > 0 && index + p1.length !== title.length &&
p1.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
title.charAt(index - 1).search(/[^\s-]/) < 0) {
return match.toLowerCase();
}
if (p1.substr(1).search(/[A-Z]|\../) > -1) {
return match;
}
return match.charAt(0).toUpperCase() + match.substr(1);
});
};
$.ajaxSetup({
cache: false
});