loadPage

/**
 * Load a template and put it in a container.
 * @param {String} templateUrl        The absolute path to the template
 * @param {String} templateId         The id of the chosen template
 * @param {jQuery} $templateContainer Empty container where the template will be placed in
 * @param {Object} viewData           The data that is loaded in the template
 *
 * @TODO: this must be refactored to a wrapper function for Mustache
 */
function loadPage(templateUrl, templateId, $templateContainer, viewData) {
	var defer = new $.Deferred();
	$.get(templateUrl, function(templates) {
		var template = $(templates).filter(templateId).html();
		var output = M.render(template, viewData);
		$templateContainer.html(output);
		defer.resolve();
	});
	return defer.promise();
}

get url parameters

function get(key) {
	var searchParams = {},
		search = window.location.search.substring(1); // substring to remove the ?

	if (search) {
		search = search.split('&');
		for (var i in search) {
			if (search.hasOwnProperty(i) && i !== '') {
				var pair = search[i].split('=');
				pair[0] = decodeURIComponent(pair[0]);
				pair[1] = decodeURIComponent(pair[1]);
				searchParams[pair[0]] = pair[1];
			}
		}
	}

	if (key) {
		return searchParams[key];
	}

	return searchParams;
}