Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gulp/scaffold/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ var taskName = 'scaffold',
insertionSuffix: '";\n'
},
registerScript: {
src: './source/assets/js/helpers/estaticoapp.js',
src: './source/assets/js/main.js',
insertionPoint: '/* autoinsertmodule */',
importInsertionPoint: '/* autoinsertmodulereference */',
insertionTemplate: 'this.modules.{{keyName}} = {{className}};\n ',
insertionTemplate: 'app.registerModuleClass({{className}}.name, {{className}});\n',
importInsertionTemplate: 'import {{className}} from \'{{modulePath}}\';\n'
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import $ from '../../../../node_modules/jquery/dist/jquery';

/**
* Init registered modules on specified events
*
* @license APLv2
*/
import $ from '../../../../node_modules/jquery/dist/jquery';

/** Demo modules **/
import SkipLinks from '../../../demo/modules/skiplinks/skiplinks';
import SlideShow from '../../../demo/modules/slideshow/slideshow';
/* autoinsertmodulereference */

class EstaticoApp {

constructor() {
Expand All @@ -20,9 +15,6 @@ class EstaticoApp {

// Module registry - mapping module name (used in data-init) to module Class
this.modules = {};
this.modules.slideshow = SlideShow;
this.modules.skiplinks = SkipLinks;
/* autoinsertmodule */

// expose initModule function
estatico.helpers.initModule = this.initModule;
Expand All @@ -33,6 +25,10 @@ class EstaticoApp {
this._initModuleInitialiser();
}

registerModuleClass(name, moduleClass) {
this.modules[name] = moduleClass;
}

initModule(moduleName, $node) {
let Module = estatico.modules[moduleName].Class,
_metaData = $node.data(moduleName + '-data') || {},
Expand Down
2 changes: 1 addition & 1 deletion source/assets/js/helpers/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EstaticoModule {
* @param {object} options - The options passed as data attribute in the Module
*/
constructor($element, _defaultData, _defaultOptions, data, options) {
this.name = this.constructor.name.toLowerCase();
this.name = this.constructor.name;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussion in #32
@orioltf, we should sit together and have a look at this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@backflip sure thing! Willing to!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@backflip just tried it in current project (didn't have a look in depth) without success. I think that removing this needs more check, so we probably need to test it in a clean project first.


this.ui = {
$element
Expand Down
12 changes: 10 additions & 2 deletions source/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import datasetPolyfill from 'element-dataset';
import '../../../node_modules/handlebars/dist/handlebars';
import './helpers/module';
import './helpers/svgspriteloader';
import EstaticoApp from './core/estaticoapp';

import EstaticoApp from './helpers/estaticoapp';
/** Demo modules **/
import SkipLinks from '../../demo/modules/skiplinks/skiplinks';
import SlideShow from '../../demo/modules/slideshow/slideshow';
/* autoinsertmodulereference */

datasetPolyfill();

let app = new EstaticoApp();
const app = new EstaticoApp();

app.registerModuleClass(SlideShow.name, SlideShow);
app.registerModuleClass(SkipLinks.name, SkipLinks);
/* autoinsertmodule */

app.start();
61 changes: 30 additions & 31 deletions source/modules/.scaffold/scaffold.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
/*!
import EstaticoModule from '../../assets/js/helpers/module';

/*
* {{originalName}}
*
* @author
* @copyright
*/
import EstaticoModule from '../../assets/js/helpers/module';

class {{className}} extends EstaticoModule {
export default class {{className}} extends EstaticoModule {
static events = {
// eventname: `eventname.estatico.${{{className}}.name}`
};
static defaultData = {};
static defaultOptions = {
domSelectors: {
// item: `[data-${{{className}}.name}}="item"]`
},
stateClasses: {
// activated: 'is_activated'
}
};

constructor($element, data, options) {
let _defaultData = {},
_name = '{{name}}',
_defaultOptions = {
domSelectors: {
// item: '[data-' + _name + '="item"]'
},
stateClasses: {
// activated: 'is_activated'
}
};

super($element, _defaultData, _defaultOptions, data, options);
super($element, {{className}}.defaultData, {{className}}.defaultOptions, data, options);

this._initUi();
this._initEventListeners();
}

static get events() {
return {
// eventname: 'eventname.estatico.' + {{name}}
};
/**
* Unbind events, remove data, custom teardown
*
* @public
*/
destroy() {
super.destroy();

// Custom destroy actions go here
}

/**
* Initialisation of variables, which point to DOM elements
*
* @private
*/
_initUi() {
// DOM element pointers
}

/**
* Event listeners initialisation
*
* @private
*/
_initEventListeners() {
// Event listeners
}

/**
* Unbind events, remove data, custom teardown
*/
destroy() {
super.destroy();

// Custom destroy actions go here
}
}

export default {{className}};