diff --git a/public_html/.htaccess b/public_html/.htaccess index 29176dc6..169fbf32 100644 --- a/public_html/.htaccess +++ b/public_html/.htaccess @@ -1,2 +1,6 @@ RewriteEngine On RewriteRule ^/?api/(.*) api-dispatch.php?q=$1 [L] + + +AddType text/html .tpl + diff --git a/public_html/index.html b/public_html/index.html index 2bf34047..12c16564 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -25,134 +25,11 @@ - - - - - - + @@ -161,6 +38,5 @@ - diff --git a/public_html/js/Presenters/LoginPresenter.js b/public_html/js/Presenters/LoginPresenter.js index 386f43d0..34ae0c08 100644 --- a/public_html/js/Presenters/LoginPresenter.js +++ b/public_html/js/Presenters/LoginPresenter.js @@ -3,6 +3,7 @@ App.Presenters = App.Presenters || {}; App.Presenters.LoginPresenter = function( jQuery, + util, topNavigationPresenter, messagePresenter, auth, @@ -13,7 +14,12 @@ App.Presenters.LoginPresenter = function( var $el = jQuery('#content'); var $messages; - var template = _.template(jQuery('#login-form-template').html()); + var template; + + util.loadTemplate('login-form').then(function(html) { + template = _.template(html); + render(); + }); var eventHandlers = { @@ -41,8 +47,6 @@ App.Presenters.LoginPresenter = function( if (appState.get('loggedIn')) router.navigateToMainPage(); - render(); - function render() { $el.html(template()); $el.find('form').submit(eventHandlers.loginFormSubmit); diff --git a/public_html/js/Presenters/RegistrationPresenter.js b/public_html/js/Presenters/RegistrationPresenter.js index 0cd531e0..1b2912f2 100644 --- a/public_html/js/Presenters/RegistrationPresenter.js +++ b/public_html/js/Presenters/RegistrationPresenter.js @@ -3,6 +3,7 @@ App.Presenters = App.Presenters || {}; App.Presenters.RegistrationPresenter = function( jQuery, + util, topNavigationPresenter, messagePresenter, api) { @@ -10,7 +11,12 @@ App.Presenters.RegistrationPresenter = function( topNavigationPresenter.select('register'); var $el = jQuery('#content'); - var template = _.template(jQuery('#registration-form-template').html()); + var template; + + util.loadTemplate('registration-form').then(function(html) { + template = _.template(html); + render(); + }); var eventHandlers = { @@ -50,8 +56,6 @@ App.Presenters.RegistrationPresenter = function( }, }; - render(); - function render() { $el.html(template()); $el.find('form').submit(eventHandlers.registrationFormSubmit); diff --git a/public_html/js/Presenters/TopNavigationPresenter.js b/public_html/js/Presenters/TopNavigationPresenter.js index 340010ed..781a8103 100644 --- a/public_html/js/Presenters/TopNavigationPresenter.js +++ b/public_html/js/Presenters/TopNavigationPresenter.js @@ -1,10 +1,15 @@ var App = App || {}; App.Presenters = App.Presenters || {}; -App.Presenters.TopNavigationPresenter = function(jQuery, appState) { +App.Presenters.TopNavigationPresenter = function(util, jQuery, appState) { var selectedElement = null; - var template = _.template(jQuery('#top-navigation-template').html()); + var template; + + util.loadTemplate('top-navigation').then(function(html) { + template = _.template(html); + render(); + }); var $el = jQuery('#top-navigation'); var eventHandlers = { @@ -14,7 +19,6 @@ App.Presenters.TopNavigationPresenter = function(jQuery, appState) { }; appState.startObserving('loggedIn', 'top-navigation', eventHandlers.loginStateChanged); - render(); function select(newSelectedElement) { selectedElement = newSelectedElement; diff --git a/public_html/js/Util.js b/public_html/js/Util.js new file mode 100644 index 00000000..f8559245 --- /dev/null +++ b/public_html/js/Util.js @@ -0,0 +1,56 @@ +var App = App || {}; + +App.Util = (function(jQuery) { + + var templateCache = {}; + + function loadTemplate(templateName) { + return loadTemplateFromCache(templateName) + || loadTemplateFromDOM(templateName) + || loadTemplateWithAJAX(templateName); + } + + function loadTemplateFromCache(templateName) { + if (templateName in templateCache) { + return new Promise(function(resolve, reject) { + resolve(templateCache[templateName]); + }); + } + } + + function loadTemplateFromDOM(templateName) { + var $template = jQuery('#' + templateName + '-template'); + if ($template.length) { + return new Promise(function(resolve, reject) { + resolve($template.html()); + }); + } + return null; + } + + function loadTemplateWithAJAX(templateName) { + return new Promise(function(resolve, reject) { + var templatesDir = '/templates'; + var templateUrl = templatesDir + '/' + templateName + '.tpl'; + var templateString; + + $.ajax({ + url: templateUrl, + method: 'GET', + success: function(data, textStatus, xhr) { + resolve(data); + }, + error: function(xhr, textStatus, errorThrown) { + console.log(Error('Error while loading template ' + templateName + ': ' + errorThrown)); + reject(); + }, + }); + }); + } + + return { + loadTemplate: loadTemplate, + }; +}); + +App.DI.registerSingleton('util', App.Util); diff --git a/public_html/templates/login-form.tpl b/public_html/templates/login-form.tpl new file mode 100644 index 00000000..20dacbda --- /dev/null +++ b/public_html/templates/login-form.tpl @@ -0,0 +1,47 @@ +
+

+ If you don't have an account yet,
+ click here to create a new one. +

+ +
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +   + + +
+
+
+ +
+

Problems logging in?

+ +
+
diff --git a/public_html/templates/registration-form.tpl b/public_html/templates/registration-form.tpl new file mode 100644 index 00000000..6a8bae28 --- /dev/null +++ b/public_html/templates/registration-form.tpl @@ -0,0 +1,50 @@ +
+

+ Registered users can view more content,
+ upload files and add posts to favorites. +

+ +
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +

+ Your e-mail will be used to show your Gravatar.
+ Leave blank for random Gravatar. +

+
diff --git a/public_html/templates/top-navigation.tpl b/public_html/templates/top-navigation.tpl new file mode 100644 index 00000000..f19aac89 --- /dev/null +++ b/public_html/templates/top-navigation.tpl @@ -0,0 +1,18 @@ +