aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--www/js/app.js49
1 files changed, 40 insertions, 9 deletions
diff --git a/www/js/app.js b/www/js/app.js
index 40633d6..a3c85be 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -13,15 +13,46 @@ var tpl = {
var loadTemplate = function (index) {
var name = names[index];
FMS.printDebug('Loading template: ' + name + ', index: ' + index);
- $.get('templates/' + CONFIG.LANGUAGE + '/' + name + '.html', function (data) {
- that.templates[name] = data;
- index++;
- if (index < names.length) {
- loadTemplate(index);
- } else {
- callback();
- }
- });
+ // Build a list of possible paths to the template, which will be tried in order.
+ var template_paths = [
+ 'templates/' + CONFIG.LANGUAGE + '/' + name + '.html'
+ ];
+ // cobrands can override the base templates by creating the appropriate file in
+ // /www/cobrands/<cobrand name>/templates/<language>, so put the cobranded template
+ // path first in the list if we're using a cobrand.
+ if (CONFIG.COBRAND) {
+ template_paths.unshift('cobrands/' + CONFIG.COBRAND + '/templates/' + CONFIG.LANGUAGE + '/' + name + '.html');
+ }
+ // Fetch a template by loading it over AJAX.
+ // Returns a jqXHR object so failures can be handed elsewhere
+ var getTemplate = function(template_path) {
+ FMS.printDebug("Fetching template: " + template_path);
+ return $.get(template_path, function (data) {
+ FMS.printDebug("success!")
+ that.templates[name] = data;
+ index++;
+ if (index < names.length) {
+ loadTemplate(index);
+ } else {
+ callback();
+ }
+ });
+ };
+
+ // Try to get the first template in template_paths, working down the list
+ // in case of failure.
+ var tryToGetTemplate = function() {
+ getTemplate(template_paths[0])
+ .fail(function() {
+ template_paths.shift();
+ if (template_paths.length) {
+ tryToGetTemplate();
+ }
+ });
+ }
+
+ // Kick-off template loading for this template.
+ tryToGetTemplate();
};
loadTemplate(0);