diff --git a/README.md b/README.md index 667c705..b09a019 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,13 @@ ## Getting ready -Run `npx http-server` and open `http://localhost:8080/` in your favorite browser! +Run `npx -p local-web-server ws` and open `http://localhost:8000/` in your favorite browser! + +## Development notes + +### Generate translations + +Run `npm run generate-translations` ## Useful links diff --git a/app/about/about.js b/app/about/about.js new file mode 100644 index 0000000..1b5b730 --- /dev/null +++ b/app/about/about.js @@ -0,0 +1,17 @@ +(function() { + // globals + MyApp.About = {}; + + + // utility functions + + // app functions + MyApp.About.renderAboutPage = function() { + $('.js-page-container').html(ejs.rr('/app/about/templates/about.ejs')); + }; + + // events + + // app startup + page('/about', MyApp.About.renderAboutPage); +})(); diff --git a/app/about/templates/about.ejs b/app/about/templates/about.ejs new file mode 100644 index 0000000..e709d8f --- /dev/null +++ b/app/about/templates/about.ejs @@ -0,0 +1,11 @@ +
This is the coolest app ever.
+ +
yay!
diff --git a/js/config.js b/app/config.js similarity index 100% rename from js/config.js rename to app/config.js diff --git a/app/index.js b/app/index.js new file mode 100644 index 0000000..4411449 --- /dev/null +++ b/app/index.js @@ -0,0 +1,55 @@ +(function() { + // globals + MyApp.Utils = {}; + + // utility functions + + // app functions + + // events + + // app startup + + // set language + i18next + .use(i18nextBrowserLanguageDetector) + .use(i18nextXHRBackend) + .init({ + detection: { + order: ['querystring', 'cookie', 'navigator'], + lookupQuerystring: 'lang', + lookupCookie: 'current-language', + caches: ['cookie'], + cookieMinutes: 5256000 + }, + whitelist: ['en', 'de', 'it'], + load: 'languageOnly', + fallbackLng: 'it', + backend: { + loadPath: '/i18n/{{lng}}.json' + } + }) + .then(function() { + // language initialized + // if there is a lang query string parameter, remove it and reload: we save the language in a cookie so the url stays nice + var urlQueryString = new URLSearchParams(window.location.search); + if (urlQueryString.has('lang')) { + urlQueryString.delete('lang'); + var newUrl = [location.protocol, '//', location.host, location.pathname].join('') + + (urlQueryString.toString() !== '' ? '?' + urlQueryString.toString() : '') + + window.location.hash; + window.location = newUrl; + return; + } + + // render main shell + MyApp.Shell.renderShell() + .then(function() { + //setup routing + page({ + hashbang: true + }); + }); + }); + +})(); diff --git a/app/shell/shell.js b/app/shell/shell.js new file mode 100644 index 0000000..3de9bd2 --- /dev/null +++ b/app/shell/shell.js @@ -0,0 +1,30 @@ +(function() { + // globals + MyApp.Shell = {}; + + // utility functions + + // app functions + MyApp.Shell.renderShell = function() { + document.title = i18next.t('vanillaJS'); + + var d = $.Deferred(); + + //preload this template, so we can be sure the dom in rendered when we resolve + ejs.preloadTemplate('/app/shell/templates/main.ejs') + .then(function(templateUrl) { + $('.js-main-content').html(ejs.rr(templateUrl)); + d.resolve(); + }); + return d; + }; + + MyApp.Shell.renderHomePage = function() { + $('.js-page-container').html(ejs.rr('/app/shell/templates/home.ejs')); + }; + + // events + + // app startup + page('/', MyApp.Shell.renderHomePage); +})(); diff --git a/app/shell/templates/home.ejs b/app/shell/templates/home.ejs new file mode 100644 index 0000000..feeac7b --- /dev/null +++ b/app/shell/templates/home.ejs @@ -0,0 +1,8 @@ +