diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c13c5f6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/Gruntfile.js b/Gruntfile.js index b68367f..1ac4a27 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,6 +33,7 @@ module.exports = function(grunt) { 'sass', 'svgstore', 'postcss', + 'babel', 'uglify', 'cssmin', 'svgmin', diff --git a/grunt_tasks/babel.js b/grunt_tasks/babel.js new file mode 100644 index 0000000..fdf7380 --- /dev/null +++ b/grunt_tasks/babel.js @@ -0,0 +1,11 @@ +module.exports = { + options: { + sourceMap: true, + presets: ['es2015'] + }, + dist: { + files: { + 'www/modules/boilerplate/assets/scripts/dist/app.js': 'www/modules/boilerplate/assets/scripts/dist/app.js' + } + } +}; diff --git a/grunt_tasks/watch.js b/grunt_tasks/watch.js index 5432307..eda48a0 100644 --- a/grunt_tasks/watch.js +++ b/grunt_tasks/watch.js @@ -1,7 +1,7 @@ module.exports = { javascript: { files: ['www/modules/boilerplate/assets/scripts/src/**/*.js'], - tasks: ['concat', 'notify:concat'] + tasks: ['concat', 'babel', 'notify:concat'] }, sass: { files: ['www/modules/boilerplate/assets/styles/src/**/*.scss'], diff --git a/package.json b/package.json index f1c99f0..ae1f237 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "author": "Locomotive ", "devDependencies": { "autoprefixer": "0.0.0", + "babel-preset-es2015": "^6.3.13", "glob": "0.0.0", "grunt": "0.0.0", + "grunt-babel": "^6.0.0", "grunt-browser-sync": "0.0.0", "grunt-contrib-concat": "0.0.0", "grunt-contrib-cssmin": "0.0.0", diff --git a/www/modules/boilerplate/assets/scripts/dist/app.js b/www/modules/boilerplate/assets/scripts/dist/app.js index 504d140..a47187f 100644 --- a/www/modules/boilerplate/assets/scripts/dist/app.js +++ b/www/modules/boilerplate/assets/scripts/dist/app.js @@ -1,18 +1,17 @@ +'use strict'; + +function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } + +/* jshint esnext: true */ // ========================================================================== // Globals // ========================================================================== var app = window.app || {}; -app.globals = { - - init : function() { - - // Global modules - // ========================================================================== - // app.parallax.init(); - - } - +app.globals = function () { + // Global app modules + // ========================================================================== + // this.parallax.init(); }; // ========================================================================== @@ -23,9 +22,7 @@ app.templates = app.templates || {}; app.templates.generic = { - init : function() { - - } + init: function init() {} }; @@ -37,79 +34,70 @@ app.widgets = app.widgets || {}; app.widgets.generic = { - init : function() { - - } + init: function init() {} }; +/* jshint esnext: true */ // ========================================================================== // App // ========================================================================== var app = window.app || {}; -app.init = function() { - - 'use strict'; - - var self = this; - - self.params = { +app.init = function () { + this.elements = { + html: document.documentElement, + body: document.body }; - self.elements = { - html : document.documentElement, - body : document.body + this.params = { + current_modules: [], + current_template: this.elements.html.getAttribute('data-template'), + current_widgets: [] }; - self.templates = self.templates || {}; - - self.widgets = self.widgets || {}; + this.templates = this.templates || {}; + this.widgets = this.widgets || {}; // Globals // ========================================================================== - if (typeof self.globals === 'object') { - self.globals.init(); + if (typeof this.globals === 'function') { + this.globals(); } // Modules // ========================================================================== - self.params.current_modules = []; - var modules = document.querySelectorAll('[data-app]'); - for (var m = 0; m < modules.length; m++) { - var dataApp = modules[m].getAttribute('data-app'); - if (typeof self[dataApp] === 'object' && self.params.current_modules.indexOf(dataApp) === -1) { - self[dataApp].init(); - self.params.current_modules.push(dataApp); - } - } + for (var i = 0, len = modules.length; i < len; i++) { + var ident = modules[i].getAttribute('data-app'); + if (_typeof(this[ident]) === 'object' && this.params.current_modules.indexOf(ident) === -1) { + this[ident].init(); + this.params.current_modules.push(ident); + } + } // Template // ========================================================================== - self.params.current_template = self.elements.body.getAttribute('data-template'); - - if (typeof self.templates[ self.params.current_template ] === 'object') { - self.templates[ self.params.current_template ].init(); + if (_typeof(this.templates[this.params.current_template]) === 'object') { + this.templates[this.params.current_template].init(); } // Widgets // ========================================================================== - self.params.current_widgets = []; - var widgets = document.querySelectorAll('[data-widget]'); - for (var w = 0; w < widgets.length; w++) { - var dataWidget = widgets[w].getAttribute('data-widget'); - if (typeof self.widgets[dataWidget] === 'object' && self.params.current_widgets.indexOf(dataWidget) === -1) { - self.widgets[dataWidget].init(); - self.params.current_widgets.push(dataWidget); - } - } + for (var i = 0, len = widgets.length; i < len; i++) { + var ident = widgets[i].getAttribute('data-widget'); + if (_typeof(this.widgets[ident]) === 'object' && this.params.current_widgets.indexOf(ident) === -1) { + this.widgets[ident].init(); + this.params.current_widgets.push(ident); + } + } }; // Init // ========================================================================== -$(function() { +$(function () { app.init(); }); +//# sourceMappingURL=app.js.map diff --git a/www/modules/boilerplate/assets/scripts/src/app.js b/www/modules/boilerplate/assets/scripts/src/app.js index 33100a6..503c8a3 100644 --- a/www/modules/boilerplate/assets/scripts/src/app.js +++ b/www/modules/boilerplate/assets/scripts/src/app.js @@ -1,66 +1,58 @@ +/* jshint esnext: true */ // ========================================================================== // App // ========================================================================== var app = window.app || {}; -app.init = function() { - - 'use strict'; - - var self = this; - - self.params = { +app.init = function () { + this.elements = { + html: document.documentElement, + body: document.body }; - self.elements = { - html : document.documentElement, - body : document.body + this.params = { + current_modules: [], + current_template: this.elements.html.getAttribute('data-template'), + current_widgets: [] }; - self.templates = self.templates || {}; - - self.widgets = self.widgets || {}; + this.templates = this.templates || {}; + this.widgets = this.widgets || {}; // Globals // ========================================================================== - if (typeof self.globals === 'object') { - self.globals.init(); + if (typeof this.globals === 'function') { + this.globals(); } // Modules // ========================================================================== - self.params.current_modules = []; - var modules = document.querySelectorAll('[data-app]'); - for (var m = 0; m < modules.length; m++) { - var dataApp = modules[m].getAttribute('data-app'); - if (typeof self[dataApp] === 'object' && self.params.current_modules.indexOf(dataApp) === -1) { - self[dataApp].init(); - self.params.current_modules.push(dataApp); - } - } + for (let i = 0, len = modules.length; i < len; i++) { + let ident = modules[i].getAttribute('data-app'); + if (typeof this[ident] === 'object' && this.params.current_modules.indexOf(ident) === -1) { + this[ident].init(); + this.params.current_modules.push(ident); + } + } // Template // ========================================================================== - self.params.current_template = self.elements.body.getAttribute('data-template'); - - if (typeof self.templates[ self.params.current_template ] === 'object') { - self.templates[ self.params.current_template ].init(); + if (typeof this.templates[this.params.current_template] === 'object') { + this.templates[this.params.current_template].init(); } // Widgets // ========================================================================== - self.params.current_widgets = []; - var widgets = document.querySelectorAll('[data-widget]'); - for (var w = 0; w < widgets.length; w++) { - var dataWidget = widgets[w].getAttribute('data-widget'); - if (typeof self.widgets[dataWidget] === 'object' && self.params.current_widgets.indexOf(dataWidget) === -1) { - self.widgets[dataWidget].init(); - self.params.current_widgets.push(dataWidget); - } - } + for (let i = 0, len = widgets.length; i < len; i++) { + let ident = widgets[i].getAttribute('data-widget'); + if (typeof this.widgets[ident] === 'object' && this.params.current_widgets.indexOf(ident) === -1) { + this.widgets[ident].init(); + this.params.current_widgets.push(ident); + } + } }; // Init diff --git a/www/modules/boilerplate/assets/scripts/src/app/globals.js b/www/modules/boilerplate/assets/scripts/src/app/globals.js index 8e251bc..e2779c7 100644 --- a/www/modules/boilerplate/assets/scripts/src/app/globals.js +++ b/www/modules/boilerplate/assets/scripts/src/app/globals.js @@ -1,16 +1,11 @@ +/* jshint esnext: true */ // ========================================================================== // Globals // ========================================================================== var app = window.app || {}; -app.globals = { - - init : function() { - - // Global modules - // ========================================================================== - // app.parallax.init(); - - } - +app.globals = function() { + // Global app modules + // ========================================================================== + // this.parallax.init(); }; diff --git a/www/modules/boilerplate/assets/scripts/src/templates/generic.js b/www/modules/boilerplate/assets/scripts/src/templates/generic.js index 493d01f..389b2ca 100644 --- a/www/modules/boilerplate/assets/scripts/src/templates/generic.js +++ b/www/modules/boilerplate/assets/scripts/src/templates/generic.js @@ -6,7 +6,7 @@ app.templates = app.templates || {}; app.templates.generic = { - init : function() { + init: function() { } diff --git a/www/modules/boilerplate/assets/scripts/src/widgets/generic.js b/www/modules/boilerplate/assets/scripts/src/widgets/generic.js index fe2bb7d..c7297a2 100644 --- a/www/modules/boilerplate/assets/scripts/src/widgets/generic.js +++ b/www/modules/boilerplate/assets/scripts/src/widgets/generic.js @@ -6,7 +6,7 @@ app.widgets = app.widgets || {}; app.widgets.generic = { - init : function() { + init: function() { }