(function() { // globals MyApp.Utils = {}; // utility functions MyApp.Utils.getUrlParameter = function(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; // app functions MyApp.renderShell = function() { document.title = i18next.t('vanillaJS'); $('.js-main-content').html(ejs.rr('/templates/main.ejs')); }; MyApp.renderHomePage = function() { $('.js-page-container').html(ejs.rr('/templates/home.ejs')); }; MyApp.renderTextPage = function() { $('.js-page-container').html(ejs.rr('/templates/sometext.ejs', { texts: [ { id: 100, description: 'Some text with id 100' }, { id: 200, description: 'Some other text with id 200. Click it!' } ] })); }; MyApp.renderAboutPage = function() { $('.js-page-container').html(ejs.rr('/templates/about.ejs')); }; // events $(document).on('click', '.js-link', function(ev) { var el = $(ev.currentTarget); var linkId = el.attr('data-id'); PNotify.success('The text you clicked had id ' + linkId + '. Maybe next time I will do something with this id.'); }); // app startup // set language i18next.init({ lng: MyApp.config.lang, resources: { en: { translation: { 'vanillaJS': 'vanillaJS seed project', 'awesome': 'This is an awesome app!' } }, it: { translation: { 'vanillaJS': 'progetto di esempio vanillaJS', 'awesome': 'Questa app รจ fantastica!' } }, de: { translation: { 'vanillaJS': 'vanillaJS Beispiel Projekt', 'awesome': 'Coole app.' } } } }); // when main content is rendered, set up routing so the app starts up $(document).arrive('.js-page-container', {existing: true, onceOnly: true}, function() { //setup routing page('/', MyApp.renderHomePage); page('/about', MyApp.renderAboutPage); page('/text', MyApp.renderTextPage); page({ hashbang: true }); }); MyApp.renderShell(); })();