Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnerd committed Sep 8, 2016
1 parent 545b147 commit db4745a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.1.0 / 2016-09-08
==================

* actions can now be bound to module element

2.0.1 / 2016-07-20
==================
Expand Down
44 changes: 22 additions & 22 deletions dist/domodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons

var Domodule = function () {
// eslint-disable-line no-unused-vars

function Domodule(el) {
var requiredOptions = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];

Expand Down Expand Up @@ -53,35 +52,17 @@ var Domodule = function () {
}, {
key: 'setupActions',
value: function setupActions() {
var _this2 = this;
this.setupAction(this.el);

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
var _loop = function _loop() {
var action = _step.value;

if (action.dataset.domoduleActionProcessed) {
return 'continue';
}

action.addEventListener(action.dataset.actionType || 'click', function (event) {
if (typeof _this2[action.dataset.action] !== 'function') {
return;
}

_this2[action.dataset.action].call(_this2, action, event, _this2.serializeAttrs('action', action));
});

action.dataset.domoduleActionProcessed = true;
};

for (var _iterator = this.find('[data-action]')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ret = _loop();
var action = _step.value;

if (_ret === 'continue') continue;
this.setupAction(action);
}
} catch (err) {
_didIteratorError = true;
Expand All @@ -98,6 +79,25 @@ var Domodule = function () {
}
}
}
}, {
key: 'setupAction',
value: function setupAction(action) {
var _this2 = this;

if (action.dataset.domoduleActionProcessed) {
return;
}

action.addEventListener(action.dataset.actionType || 'click', function (event) {
if (typeof _this2[action.dataset.action] !== 'function') {
return;
}

_this2[action.dataset.action].call(_this2, action, event, _this2.serializeAttrs('action', action));
});

action.dataset.domoduleActionProcessed = true;
}
}, {
key: 'setupNamed',
value: function setupNamed() {
Expand Down
3 changes: 2 additions & 1 deletion example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export default class Example extends Domodule { // eslint-disable-line no-unused
console.log(this.els);
}

click(el, event, values) {
click(el, event, values = {}) {
console.log('clicked', el, values);

console.log(`clicked index ${values.index}`);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body>

<div id="ExampleModule" data-module="Example" data-module-test="true" data-module-title="Example Module" data-module-global-screen="screen">
<div id="ExampleModule" data-module="Example" data-module-test="true" data-module-title="Example Module" data-module-global-screen="screen" data-action="click">
<div data-action="testMouseOver" data-action-type="mouseover" style="height: 100px; width: 100px; background: black"></div>
<div data-name="tester"></div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions example/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ test('actions', assert => {
assert.end();
});

test('action on module', assert => {
window.logHistory = [];
Domodule.getInstance(document.getElementById('ExampleModule')).click();
assert.ok(window.logHistory.indexOf('clicked') !== -1, 'Action fired on event');
assert.ok(document.getElementById('ExampleModule').dataset.domoduleActionProcessed, 'Should have processed = true');

assert.end();
});

test('refs', assert => {
assert.ok(typeof Domodule.refs !== 'undefined' && Domodule.refs instanceof Object, 'Refs object exists');
assert.ok(Domodule.getInstance(document.getElementById('ExampleModule')) instanceof Domodule, 'getInstance returns module instance');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "domodule",
"version": "2.0.1",
"version": "2.1.0",
"description": "Class based modules",
"main": "lib/domodule.js",
"keywords": [
Expand Down

0 comments on commit db4745a

Please sign in to comment.