Skip to content

Commit

Permalink
added simply.keyboard
Browse files Browse the repository at this point in the history
added simply-edit.js in counter and keyboard example, since simplyview no longer contains databinding
  • Loading branch information
poef committed Dec 5, 2021
1 parent 27a04be commit a4d5185
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 36 deletions.
48 changes: 47 additions & 1 deletion dist/simply.everything.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,51 @@ properties for a given parent, keep seperate index for this?
}

})(this);
(function(global) {
'use strict';

function keyboard(app, config) {
var keys = config;

if (!app) {
app = {};
}
if (!app.container) {
app.container = document.body;
}
app.container.addEventListener('keydown', (e) => {
if (e.isComposing || e.keyCode === 229) {
return;
}
if (e.defaultPrevented) {
return;
}
if (!e.target) {
return;
}

let selectedKeyboard = 'default';
if (e.target.closest('[data-simply-keyboard]')) {
selectedKeyboard = e.target.closest('[data-simply-keyboard]').dataset.simplyKeyboard;
}
if (keys[selectedKeyboard] && keys[selectedKeyboard][e.code]) {
keys[selectedKeyboard][e.code].call(app,e);
}
});

return keys;
}


if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = keyboard;
} else {
if (!global.simply) {
global.simply = {};
}
global.simply.keyboard = keyboard;
}
})(this);
(function(global) {
'use strict';

Expand Down Expand Up @@ -1986,7 +2031,8 @@ properties for a given parent, keep seperate index for this?
simply.route.match(global.location.pathname+global.location.hash);
});
}
this.container = options.container || document.body;
this.container = options.container || document.body;
this.keyboard = simply.keyboard ? simply.keyboard(this, options.keyboard || {}) : false;
this.actions = simply.action ? simply.action(this, options.actions) : false;
this.commands = simply.command ? simply.command(this, options.commands) : false;
this.resize = simply.resize ? simply.resize(this, options.resize) : false;
Expand Down
33 changes: 0 additions & 33 deletions docs/index.md

This file was deleted.

1 change: 1 addition & 0 deletions examples/counter.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h2>Counter</h2>
<div>Counter is now: <span data-simply-field="counter"></span></div>
</div>

<script src="//cdn.simplyedit.io/1/simply-edit.js"></script>
<script src="../dist/simply.everything.js"></script>
<script>
var counterApp = simply.app({
Expand Down
3 changes: 2 additions & 1 deletion js/simply.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
simply.route.match(global.location.pathname+global.location.hash);
});
}
this.container = options.container || document.body;
this.container = options.container || document.body;
this.keyboard = simply.keyboard ? simply.keyboard(this, options.keyboard || {}) : false;
this.actions = simply.action ? simply.action(this, options.actions) : false;
this.commands = simply.command ? simply.command(this, options.commands) : false;
this.resize = simply.resize ? simply.resize(this, options.resize) : false;
Expand Down
45 changes: 45 additions & 0 deletions js/simply.keyboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(function(global) {
'use strict';

function keyboard(app, config) {
var keys = config;

if (!app) {
app = {};
}
if (!app.container) {
app.container = document.body;
}
app.container.addEventListener('keydown', (e) => {
if (e.isComposing || e.keyCode === 229) {
return;
}
if (e.defaultPrevented) {
return;
}
if (!e.target) {
return;
}

let selectedKeyboard = 'default';
if (e.target.closest('[data-simply-keyboard]')) {
selectedKeyboard = e.target.closest('[data-simply-keyboard]').dataset.simplyKeyboard;
}
if (keys[selectedKeyboard] && keys[selectedKeyboard][e.code]) {
keys[selectedKeyboard][e.code].call(app,e);
}
});

return keys;
}


if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = keyboard;
} else {
if (!global.simply) {
global.simply = {};
}
global.simply.keyboard = keyboard;
}
})(this);
1 change: 1 addition & 0 deletions make
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cat js/simply.observe.js \
js/simply.activate.js \
js/simply.collect.js \
js/simply.command.js \
js/simply.keyboard.js \
js/simply.action.js \
js/simply.resize.js \
js/simply.include.js \
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": "simplyview",
"version": "2.0.0",
"version": "2.0.2",
"description": "Library to rapidly build UI components, using declarative tools",
"main": "dist/simply.everything.js",
"directories": {
Expand Down

0 comments on commit a4d5185

Please sign in to comment.