Skip to content

Commit

Permalink
Merge pull request #114 from automata/gh-pages
Browse files Browse the repository at this point in the history
ui-makeymakey
  • Loading branch information
Forrest Oliphant committed Apr 29, 2013
2 parents 62f5dd7 + 720ac06 commit d3c8e2d
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/examples/module-library.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions src/nodes/ui-makeymakey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*global Stats:true*/

// extends src/nodes/time.js which extends src/node-box-native-view.js

$(function(){

var template =
'<b>makeymakey</b><br /><div class="info"></div>'+
'<label><input type="checkbox" class="active" checked /> active</label>';;

Iframework.NativeNodes["ui-makeymakey"] = Iframework.NativeNodes["ui"].extend({

template: _.template(template),
info: {
title: "makeymakey",
description: "makeymakey board"
},
events: {
"change .active": "changeActive"
},
initializeModule: function(){
var self = this;

Mousetrap.bind('space', function () {
if (self._active) {
self.sendSpace();
}
});

Mousetrap.bind('up', function () {
if (self._active) {
self.sendUp();
}
});

Mousetrap.bind('down', function () {
if (self._active) {
self.sendDown();
}
});

Mousetrap.bind('right', function () {
if (self._active) {
self.sendRight();
}
});

Mousetrap.bind('left', function () {
if (self._active) {
self.sendLeft();
}
});

$(window).click(function (event) {
if (self._active) {
self.sendClick(event);
}
});
},
_active: true,
changeActive: function(event){
if (event.target.checked) {
this._active = true;
} else {
this._active = false;
}
},
sendSpace: function() {
this.send("space", "bang");
this.$(".info").text('Space!');
},
sendClick: function(evt) {
this.send("click", "bang");
this.$(".info").text('Click!');
},
sendUp: function() {
this.send("up", "bang");
this.$(".info").text('Up!');
},
sendDown: function() {
this.send("down", "bang");
this.$(".info").text('Down!');
},
sendLeft: function() {
this.send("left", "bang");
this.$(".info").text('Left!');
},
sendRight: function() {
this.send("right", "bang");
this.$(".info").text('Right!');
},
remove: function() {
var keys = ['space', 'up', 'down', 'left', 'right'];
for (key in keys) {
Mousetrap.unbind(key, 'keydown');
}
$(window).unbind('click');
},
outputs: {
space: {
type: "bang"
},
click: {
type: "bang"
},
up: {
type: "bang"
},
down: {
type: "bang"
},
left: {
type: "bang"
},
right: {
type: "bang"
}
}
});
});

0 comments on commit d3c8e2d

Please sign in to comment.